iOS13,Xcode11安裝後變化和老項目兼容

1,首先是登錄的界面出現了presentviewcontroller後就會導致半屏幕顯示

 LoginViewController *loginCtrl = [[LoginViewController alloc ] init];
        UINavigationController *presentCtrl = [[UINavigationController alloc] initWithRootViewController:loginCtrl];

//這段代碼很重要,modalPresentationStyle就是改變了跳轉頁的樣式,是否是全屏頁面
        presentCtrl.modalPresentationStyle = UIModalPresentationFullScreen;

        [self presentViewController:presentCtrl animated:YES completion:^{
        }];

2,對於新的版本後,老得代碼多了SceneDelegate.h 和SceneDelegate.m文件,歸結原因,蘋果開發者平臺把app的功能調用和界面UI調用分開來了,這是爲了以後對一個界面顯示多個app做準備,一個appDelegate能控制多個SceneDelegate。對於解決辦法,可以把info.plist文件中把關於SceneDelegate的鏈接(Application Scene Manifest)去掉,然後刪除SceneDelegate.h 和SceneDelegate.m文件,這樣就可以跟更新版本前一樣了

3,關於加載圖像如果出現黑屏或者屏幕展示效果會有上下兩道黑條,這是由於LaunchImage沒法自動匹配當前的圖片的Frame導致的,也可能是由於圖片尺寸不對,導致獲取不到圖片的Frame,建議直接改用LaunchScreen來配置啓動圖片,不建議再去修改LaunchImage,蘋果開發文檔表示:2020年4月份將會取消LaunchImage的使用

4對於私有的kvc問題,主要體現在對textplacehoder的字體大小和顏色設置上,

//修改textField的佔位符字體顏色
[textField setValue:[UIColor xxx] forKeyPath:@"_placeholderLabel.textColor"];

 iOS13中通過KVC方式來獲取私有屬性,有Carsh風險,儘量避免使用.比如我們常用的UITextFiled和UISearchController等,在iOS 13的searchbar添加了一個- (void)set_cancelButtonText:(NSString *)text方法,這個方法專門用來命中kvc,一旦命中就Crash

搜了搜,感覺這個回答的最好:

(1).獲取SearchBar的textField

由於在13中把SearchBar中的textField直接暴露給開發者使用,無需在通過kvc獲取。

- (UITextField *)sa_GetSearchTextFiled{
    if ([[[UIDevice currentDevice]systemVersion] floatValue] >=     13.0) {
        return self.searchTextField;
    }else{
    UITextField *searchTextField = [self valueForKey:@"_searchField"];
        return searchTextField;
    }
}

(2).修改TextFiled的佔位符字體大小以及顏色,在iOS13中不能通過KVC來進行修改,可以通過其屬性字符串來進行修改

UITextField *textfield = [[UITextField alloc]init];
NSMutableAttributedString *arrStr = [[NSMutableAttributedString alloc]initWithString:textfield.placeholder attributes:@{NSForegroundColorAttributeName : [UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:12]}];
textfield.attributedPlaceholder = arrStr;

(3).獲取SearchBar的cancleButton,由於searcBar的層級發生變化以及對象的局部變量,因爲無法通過kvc的方式來獲取

if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 13.0) {
  for(id cc in [self.searchBar subviews]) {
    for (id zz in [cc subviews]) {
      for (id gg in [zz subviews]) {
        if([gg isKindOfClass:[UIButton class]]){
          UIButton *cancelButton = (UIButton *)gg;
          [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }
      }
    }
  }
}else{
  UIButton*cancelButton = (UIButton *)[self.searchBar getVarWithName:@"_cancelButton"];
  [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}

5,MPMoviePlayerController在iOS13中廢棄

MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.
在iOS13中對於MPMoviePlayerController使用的廢棄,需要使用AVKit中的AVPlayerViewController來達到播放的目的。

6,增加一直使用藍牙的權限申請

CBCentralManager,iOS13以前,使用藍牙時可以直接用,不會出現權限提示,iOS13後,再使用就會提示了。在info.plist裏增加NSBluetoothAlwaysUsageDescription

 7,(很新)iOS夜間模式開發探索(iOS13)

override func viewDidLoad() {
        super.viewDidLoad()

        // Always adopt a light interface style.    
        overrideUserInterfaceStyle = .light
}

以後繼續更新...........

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