Xcode8的改动以及适配

2016-09-19  本文已影响222人  U小姐咯

宝宝今天上午更新到了Xcode8.0了,然后根据前人经验加上自己的调试总结如下.
🍒运行程序,你发现什么都没做就会打印出来一大推东西,当然我们可以剔除它们.
method: Product => Scheme =>Run => Arguments, 在Environment Variables里边添加OS_ACTIVITY_MODE = Disable

删除多余的log.png
🍒关于statusBar
首先在info.plist中加入View controller-based status bar appearance = No;
我们可以发现,@property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]") __TVOS_PROHIBITED;苹果官方让我们改变之前设置的方法了,我们该怎么做呢.
在需要设置的vc中写入对应的方法
-(UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

在App delegate中进行设置

  ViewController *vc = [[ViewController alloc]init];
    self.window.rootViewController = vc;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [UIApplication sharedApplication].statusBarStyle = [vc preferredStatusBarStyle];

🍒新增的DataSourcePrefetching(适用于collectionView和tableview),这个协议并不能代替之前读取数据的方法,仅仅是辅助加载数据

- (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPath{
    //NS_AVAILABLE_IOS(10_0),require
    
    //开始此方法是预加载(页面上显示的cell的数量-每行显示cell的数量)
    //eg:瀑布流是每行两个cell排列的,并且页面显示了8个cell,那么预加载打印的就是item为(8~13)
    for (NSIndexPath *index in indexPath) {
        NSLog(@"%ld",(long)index.item);
    }
    //滑动显示打印的item的cell是显示的是每行显示的cell数量(上述例子滑动加载的就是<14,15>,<16,17>.......)
}

- (void)collectionView:(UICollectionView *)collectionView cancelPrefetchingForItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths{
    // NS_AVAILABLE_IOS(10_0); @optional
//这个方法是可选的,可以用来处理在滑动中取消或者降低提前加载数据的优先级.
}

🍒刷新控件(同样适用于collectionView和tableview),RefreshControl是UIScrollView的一个属性

 UIRefreshControl *refreshCtrol = [[UIRefreshControl alloc]init];
    [refreshCtrol addTarget:self action:@selector(refrshData) forControlEvents:UIControlEventValueChanged];
    //这个可以改变风火轮的颜色;
    refreshCtrol.tintColor = [UIColor blueColor];
    NSAttributedString *title = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
    //设置下拉时候可以显示的文字,显示在风火轮的下面
    refreshCtrol.attributedTitle = title;
    self.collection.refreshControl = refreshCtrol;
    _refreshCtrol = refreshCtrol;
-(void)refrshData{
    for (int i = 0; i < 5; i ++) {
        NSString *str = @"little prince";
        [_dataSource addObject:str];
    }
//模拟数据的请求网络延迟的情况
    [self performSelector:@selector(delay) withObject:nil afterDelay:2];
}
-(void)delay{
    [_refreshCtrol endRefreshing];
    [self.collection reloadData];
}

🍒苹果公司增强用户隐私和安全.在对权限的设置都需要在info.plist中加上对应的key值,value可以自定义.下面把所有的key值列出来

<-- 相册 --> 
<key>NSPhotoLibraryUsageDescription</key> 
<string>是否同意访问相册</string> 
<-- 相机 --> 
<key>NSCameraUsageDescription</key> 
<string>是否同意访问相机</string> 
<-- 麦克风 --> 
<key>NSMicrophoneUsageDescription</key> 
<string>是否同意访问麦克风</string> 
<-- 位置 --> 
<key>NSLocationUsageDescription</key> 
<string>是否同意访问位置</string> 
<-- 在使用期间访问位置 --> 
<key>NSLocationWhenInUseUsageDescription</key> 
<string>是否同意使用期间访问位置</string> 
<-- 始终访问位置 --> 
<key>NSLocationAlwaysUsageDescription</key> 
<string>是否同意始终访问位置</string> 
<-- 日历 --> 
<key>NSCalendarsUsageDescription</key> 
<string>是否同意访问日历</string> 
<-- 提醒事项 --> 
<key>NSRemindersUsageDescription</key> 
<string>是否同意访问提醒事项</string> 
<-- 运动与健身 --> 
<key>NSMotionUsageDescription</key>
 <string>是否同意访问运动与健身</string> 
<-- 健康更新 --> 
<key>NSHealthUpdateUsageDescription</key> 
<string>App是否同意访问健康更新 </string> 
<-- 健康分享 --> 
<key>NSHealthShareUsageDescription</key> 
<string>是否同意访问健康分享</string> 
<-- 蓝牙 --> 
<key>NSBluetoothPeripheralUsageDescription</key> 
<string>是否同意访问蓝牙</string> 
<-- 媒体资料库 --> 
<key>NSAppleMusicUsageDescription</key> 
<string>是否同意访问媒体资料库</string>

🍒还有的等我发现了再总结咯
以上😁

上一篇 下一篇

猜你喜欢

热点阅读