Xcode9 iOS11适配

作者: 墨狂之逸才 | 来源:发表于2017-11-22 22:51 被阅读59次

    1.iOS11UIToolBar上添加的按钮点击实效

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        UIToolbar *toolBar = [[UIToolbar alloc] init];
        toolBar.backgroundColor = [UIColor cyanColor];
        toolBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 200);
        [self.view addSubview:toolBar];
        
        UIButton *button = [[UIButton alloc] init];
        button.frame = CGRectMake(0, 0, 100, 200);
        button.backgroundColor = [UIColor orangeColor];
        [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
        [toolBar addSubview:button];
        
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)buttonClick {
        NSLog(@"我点击按钮了哦!!!,我真的点击了哦");
    }
    

    测试总结:iOS11一下按钮可以正常点击
    iOS11以上按钮点击无法响应。
    这个问题我是在修改别人代码的时候发现的。

    2.iOS11 window上的视图结构发生了变化

    iOS11

    (lldb) po [UIApplication sharedApplication].keyWindow
    <UIWindow: 0x10260c0f0; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = <NSArray: 0x1c4245b50>; layer = <UIWindowLayer: 0x1c402c380>>
    
    (lldb) po [UIApplication sharedApplication].windows[0]
    <UIWindow: 0x10260c0f0; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = <NSArray: 0x1c4245b50>; layer = <UIWindowLayer: 0x1c402c380>>
    
    (lldb) po [UIApplication sharedApplication].windows[1]
    <UITextEffectsWindow: 0x1025a7fe0; frame = (0 0; 414 736); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x1c023dc60>>
    
    (lldb) po [UIApplication sharedApplication].windows[2]
    <_UIInteractiveHighlightEffectWindow: 0x10268d030; frame = (0 0; 414 736); hidden = YES; opaque = NO; userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x1c444ae30>; layer = <UIWindowLayer: 0x1c403bf20>>
    
    (lldb) po [UIApplication sharedApplication].windows[3]
    error: Execution was interrupted, reason: internal ObjC exception breakpoint(-4)..
    The process has been returned to the state before expression evaluation.
    

    iOS11以下

    (lldb) po [UIApplication sharedApplication].keyWindow
    <UIWindow: 0x153d0c360; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x174050aa0>; layer = <UIWindowLayer: 0x174029520>>
    
    
    (lldb) po [UIApplication sharedApplication].windows
    <__NSArrayM 0x170257220>(
    <UIWindow: 0x153d0c360; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x174050aa0>; layer = <UIWindowLayer: 0x174029520>>
    )
    
    (lldb) po [UIApplication sharedApplication].windows[0]
    <UIWindow: 0x153d0c360; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x174050aa0>; layer = <UIWindowLayer: 0x174029520>>
    
    (lldb) po [UIApplication sharedApplication].windows[1]
    error: Execution was interrupted, reason: internal ObjC exception breakpoint(-3)..
    The process has been returned to the state before expression evaluation.
    

    这个问题是在发现之前写的MBProgressHUD怎么突然不行了,在iOS11不能出现和iOS11以下可以出现

    + (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    //iOS11以下windows里面新增加了成员
    //    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
        if (view == nil) view = [UIApplication sharedApplication].keyWindow;
        // 快速显示一个提示信息
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
        hud.labelText = message;
        // 隐藏时候从父控件中移除
        hud.removeFromSuperViewOnHide = YES;
        // YES代表需要蒙版效果
        hud.dimBackground = YES;
        return hud;
    }
    

    相关文章

      网友评论

        本文标题:Xcode9 iOS11适配

        本文链接:https://www.haomeiwen.com/subject/dwpiextx.html