国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS開發中遇到的問題整理

2019-11-09 17:57:55
字體:
來源:轉載
供稿:網友
1、@try @catch @finally 的用途是?      答:Handling Exception (處理異常)  https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/Exceptions/Tasks/HandlingExceptions.html#//apple_ref/doc/uid/20000059-BBCHGJIJhttps://developer.apple.com/library/mac/documentation/cocoa/Conceptual/Exceptions/Exceptions.html2、如何用GCD創建一個單例方法?      答:+ (SVPRogressHUD*)sharedView   {    static dispatch_once_t once;    static SVProgressHUD *sharedView;    dispatch_once(&once, ^ { sharedView = [[SVProgressHUD alloc] initWithFrame:[[UIScreen           mainScreen] bounds]]; });    return sharedView;    }3、多線程下防止單例被同時調用怎么辦?      答:可以加一個線程鎖   @synchronized(self)  或 NSLock 4、枚舉如何定義?      答:typedef enum  {      //以下是枚舉成員      TestA = 0,      TestB,      TestC,      TestD  }Test;//枚舉名稱  亦可以如下定義(推薦:結構比較清晰):typedef NS_ENUM(NSInteger, Test1)  {      //以下是枚舉成員      Test1A = 0,      Test1B = 1,      Test1C = 2,      Test1D = 3  };  枚舉的定義還支持位運算的方式定義,如下:

等于號后面必須等于1typedef NS_ENUM(NSInteger, Test)  {      TestA       = 1,      //1   1   1      TestB       = 1 << 1, //2   2   10      轉換成 10進制  2      TestC       = 1 << 2, //4   3   100     轉換成 10進制  4      TestD       = 1 << 3, //8   4   1000    轉換成 10進制  8      TestE       = 1 << 4  //16  5   10000   轉換成 10進制  16  }; 5、動態加載xib?     答:self.view = [[[NSBundle mainBundle]loadNibNamed:@"RecommednViewController" owner:self options:nil]lastObject]; 同時需要關聯xib為該controller6、if else 與 switch case 區別??     答:if-else結構中,條件判斷部分可以是任何符合語法的表達式。switch-case結構中,switch括號中以及case右邊的表達式必須是常量表達式。如果條件判斷所用的表達式并非常量,那么不能用switch-case,只能用if-else。7、GoogleMaps常用的類?     答:GMSCameraPosition (確定即將呈現地圖的位置)             GMSMapView (地圖視圖)             GMSMapViewDelegate  (代理)             GMSMutablePath  (點與點之間的路徑)             GMSPolyline  (呈現路徑的線條)             GMSMarker   (地圖上的小icon)             CLLocationDegrees (封裝坐標點)          CLLocation (坐標)             CLGeocoder (通過坐標來進行城市解碼)             CLPlacemark  (儲存的城市信息)             CLLocationManager  8、RunLoop 的使用,如何阻塞當前線程??     答:NSRunLoop * asyRunLoop=[NSRunLoop currentRunLoop];                                while (pause)                {                                        [asyRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];                                    }9、iOS autoresizingMask與autoLayout的區別?     答:autoresizingMask是子視圖的左、右、上、下邊距以及寬度和高度相對于父視圖按比例變化            UIViewAutoresizingNone (不自動調整)                       autoLayout是子視圖相對于某個視圖(可以是父視圖也可以是同級兄弟視圖)的位置,在屏                幕尺寸發生變化時,相對位置保持不變           //在頁面水平居中顯示按鈕。         [self.viewaddConstraint: [NSLayoutConstraintconstraintWithItem:self.btn                                                          attribute:NSLayoutAttributeCenterX                                                          relatedBy:NSLayoutRelationEqual                                                             toItem:self.view                                                          attribute:NSLayoutAttributeCenterX                                                         multiplier:1.0                                                           constant:0]];10、如何實現微信搖一搖功能?      答:AVAudiosession *audioSession = [AVAudioSession sharedInstance];    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL];    player=[[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];    [player prepareToPlay];    player.volume = .8;    [player play];     11、圖片移動的動畫效果?     答://讓imagdown上下移動    CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"position"];    translation.timingFunction = [CAMediaTimingFunction           functionWithName:kCAMediaTimingFunctionEaseInEaSEOut];    translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(160, 345)];    translation.toValue = [NSValue valueWithCGPoint:CGPointMake(160, 420)];    translation.duration = 0.5;    translation.repeatCount = 1;    translation.autoreverses = YES;    [_imgDown.layer addAnimation:translation forKey:@"translation"];11、如何適配IOS6.0 和IOS7.0 ,以及3.5inch 和4.0inch的屏幕?     答:   方法一:        int width = [[UIScreen mainScreen] bounds].size.width;    int height = [[UIScreen mainScreen] bounds].size.height; if (IOS7_EARLY) {               _myTabelview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0 , width , height - 64 - 49 ) style:UITableViewStyleGrouped];    }    else    _myTabelview = [[UITableView alloc] initWithFrame:CGRectMake(0, 64 , width , height  - 64 -49) style:UITableViewStyleGrouped]; 方法二:    UIView *bgView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds]; if (IOS7_EARLY) {                _myTabelview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0 , 320, CGRectGetHeight(bgView.frame)- 64 - 49 ) style:UITableViewStyleGrouped];    }    else    _myTabelview = [[UITableView alloc] initWithFrame:CGRectMake(0, 64 , 320, CGRectGetHeight(bgView.frame) - 64 -49) style:UITableViewStyleGrouped];12、靜態方法和實例化方法的區別??     答: 從線程安全、性能、兼容性上來看 也是選用實例化方法為宜。     早期的結構化編程,幾乎所有的方法都是“靜態方法”,引入實例化方法概念是面向對象概念出現以后的事情了,區分靜態方法和實例化方法不能單單從性能上去理解,創建c++,java,c#這樣面向對象語言的大師引入實例化方法一定不是要解決什么性能、內存的問題,而是為了讓開發更加模式化、面向對象化。這樣說的話,靜態方法和實例化方式的區分是為了解決模式的問題。拿別人一個例子說事:比如說“人”這個類,每個人都有姓名、年齡、性別、身高等,這些屬性就應該是非靜態的,因為每個人都的這些屬性都不相同;但人在生物學上屬于哪個門哪個綱哪個目等,這個屬性是屬于整個人類,所以就應該是靜態的——它不依賴與某個特定的人,不會有某個人是“脊椎動物門哺乳動物綱靈長目”而某個人卻是“偶蹄目”的。     http://blog.csdn.net/biaobiaoqi/article/details/6732117 13、如何一次性將NSLog語句移除?     答:在-Prefix.pch文件中加入以下代碼:#ifdef DEBUG#    define DLog(...) NSLog(__VA_ARGS__)#else#    define DLog(...) /* */#endif#define ALog(...) NSLog(__VA_ARGS__)14、typedef void (*comm_callback)(char*, int, void*); 是什么意思 ?      答:定義一個函數指針類型comm_callback這個函數類型是這樣:返回值void 參數:char*,int,void*可以直接使用comm_callback定義一個函數指針如:comm_callback pFun;http://modernrobber.blog.163.com/blog/static/214636320071125112629565/http://blog.csdn.net/u011344883/article/details/25103383 (函數指針右左法則)15、雙向鏈表是怎樣的?      答:線性表的雙向鏈表存儲結構typedef struct DuLNode{ElemType data;struct DuLNode *prior,*next;}DuLNode,*DuLinkList;16、正則表達式??      答:NSString *phoneRegex = @"^((13[0-9])|(15[^4,//D])|(18[0,0-9]))//d{8}$";              NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES                          %@",phoneRegex];              return [phoneTest evaluateWithObject:mobile];17、鍵盤的顯示和隱藏,動畫效果?     答:const float movementDuration = .3f;    [UIView beginAnimations:@"anim" context:nil];    [UIView setAnimationBeginsFromCurrentState:YES];    [UIView setAnimationDuration:movementDuration];     //一個動畫的運動隨時間快慢曲線      [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];       //動畫方式     [UIView setAnimationTransition:UIViewAnimationOptionTransitionCurlUp forView:self.view cache:YES];      view.frame = CGRectOffset(view.frame, 0, distance);    [UIView commitAnimations];18、textView高度自適應??     答:IOS6 可用contentSize.height 來自適應,但是不適用于IOS7            IOS7  的方法如下:- (CGSize)contentSizeOfTextView:(UITextView *)textView{    CGSize textViewSize = [textView sizeThatFits:CGSizeMake(textView.frame.size.width, FLT_MAX)];    return textViewSize;}19、NSClassFromString 和 NSSelectorFromString 的區別??NSClassFromStringNSSelectorFromString 正常來說,id myObj = [[NSClassFromString(@"MySpecialClass") alloc] init];和id myObj = [[MySpecialClass alloc] init];是一樣的。但是,如果你的程序中并不存在MySpecialClass這個類,下面的寫法會出錯,而上面的寫法只是返回一個空對象而已。因此,在某些情況下,可以使用NSClassFromString來進行你不確定的類的初始化。比如在iPhone中,NSTask可能就會出現這種情況,所以在你需要使用NSTask時,最好使用:[[NSClassFromString(@"NSTask") .....]]而不要直接使用[NSTask ...]這種寫法。NSClassFromString的好處是:1 弱化連接,因此并不會把沒有的Framework也link到程序中。2 不需要使用import,因為類是動態加載的,只要存在就可以加載。20、CATransaction 的用處??     答:CATransaction 事務類,可以對多個layer的屬性同時進行修改.它分隱式事務,和顯式事務       [CATransaction begin];       [CATransaction setAnimationDuration:3.f];  // 3 second animation       GMSCameraPosition *camera =           [[GMSCameraPosition alloc] initWithTarget:marker.position                                           zoom:8                                        bearing:50                                   viewingAngle:60];       [mapView animateToCameraPosition:camera];       [CATransaction commit];     http://www.cnblogs.com/bandy/archive/2012/03/26/2418165.html
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 固阳县| 三原县| 连江县| 巴林左旗| 长海县| 正宁县| 柳江县| 即墨市| 阳泉市| 淮滨县| 萨迦县| 马关县| 柳林县| 巨鹿县| 剑河县| 大丰市| 隆德县| 正阳县| 肇源县| 固原市| 周宁县| 郧西县| 泗水县| 胶州市| 宁南县| 龙海市| 杭锦旗| 黄石市| 潮安县| 五华县| 新郑市| 佛坪县| 乌鲁木齐市| 深水埗区| 渑池县| 黄山市| 乌海市| 芜湖市| 满城县| 天等县| 阜城县|