iphone技術總結, 在網上找到比較有用的東東,整合一下

iphone技術總結

1.    讓下面圖層可以觸摸

searchImage.exclusiveTouch = YES;//第一層
searchImage.userInteractionEnabled = NO;
myMapView.exclusiveTouch = NO;//
第二層
myMapView.userInteractionEnabled = YES;

 

2.    設置狀態欄

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];//隱藏狀態欄

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];//設置狀態欄透明

 

3.   判斷網絡是否連接

+(BOOL)isExistenceNetwork{

         BOOL isExistenceNetwork;

         Reachability *reachability=[Reachability reachabilityWithHostName:@""];

        

         switch ([reachability currentReachabilityStatus]) {

              case NotReachable:

                     isExistenceNetwork=FALSE;

                     break;

              case ReachableViaWWAN:

                  isExistenceNetwork=TRUE;

                     break;

        case ReachableViaWiFi:

                     isExistenceNetwork=TRUE;

                     break;

         }

        

         return isExistenceNetwork;

}

注:需要導入Reachability

 

4.    實時通知網絡狀況

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   

     ....................

         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];

    reachability=[[Reachability reachabilityWithHostName:@"www.baidu.com"] retain];

         [reachability startNotifier];

         return YES;

}

-(void)reachabilityChanged:(NSNotification *)notification{

         Reachability *curReachability=[notification object];

         NSParameterAssert([curReachability isKindOfClass:[Reachability class]]);

         NetworkStatus curStatus=[curReachability currentReachabilityStatus];

         if (curStatus==NotReachable) {

              [DOIN_Util logFax:@"連接失敗"];

         }

}

注:以上需要Reachability類在2.0以上纔可以適用 


6.    顯示和隱藏UITabBarController

   secondViewController.hidesBottomBarWhenPushed=YES

    其中的secondViewController爲需要隱藏tabbar的視圖,如果全部視圖都需要隱藏,那麼可以使用self.hidesBottomBarWhenPushed=YES來實現。

注:缺點就是隱藏tabbar的視圖不能在顯示tabbar

 

7.    UINavigationController顯示爲透明狀態或者隱藏

    navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent

   其中 navigationController爲一個UINavigationController對象,通過上述代碼可以使導航欄背景處於透明狀態。

   [self.navigationController setNavigationBarHidden:NO animated:YES];

   上述代碼可以把navigationController隱藏起來,如果把其中的NO改爲YES就可以顯示出來

 

8.    UINavigationController中的toolbar設置透明 [self.navigationController.toolbar setTranslucent:YES];設置爲透明

 

9.    iPhone App中提醒用戶打分或寫評價的方法 

用戶使用了軟件卻不到 App Store 打分或是寫評論是很令開發者頭疼的。下面這個方法能在 iPhone App 中集成提醒功能,彈出文字框來提示沒有打分的用戶。

主要代碼

 [[CloudReview sharedReview]reviewFor:395519376];

 

 CloudReview.h

 #import <Foundation/Foundation.h>  
  #import <UIKit/UIKit.h>  

 

@interface CloudReview : NSObject {  
     int m_appleID;  
  
 +(CloudReview*)sharedReview;  
 -(void) reviewFor:(int)appleID;  
 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;  
 @end

CloudReview.m

#import "CloudReview.h"  
  
@implementation CloudReview  
static CloudReview* _sharedReview = nil;  
 +(CloudReview*)sharedReview  
  
     @synchronized([CloudReview class])  
     {  
         if (!_sharedReview)  
             [[self alloc] init];  
           
         return _sharedReview;  
     }  
       
     return nil;  
  
 +(id)alloc  
  
     @synchronized([CloudReview class])  
     {  
         NSAssert(_sharedReview == nil, @"Attempted to allocate a second instance of a singleton.");  
         _sharedReview = [super alloc];  
         return _sharedReview;  
     }  
       
     return nil;  
  
 -(void)reviewFor:(int)appleID  
  
     m_appleID = appleID;  
     BOOL neverRate = [[NSUserDefaults standardUserDefaults] boolForKey:@"neverRate"];  
     if(neverRate != YES) {  
         //Show alert here  
         UIAlertView *alert;  
         alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"rate_title",@"Rate My Appication")  
                             

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章