iOS8.1- iOS8.3横屏后部分区域无响应bug 解决办法

本文介绍了解决iOS 8.1至8.3版本中,因使用特定方法设置屏幕旋转而导致Home键下半部分点击事件失效的问题。通过重写hitTest方法转移点击坐标,确保点击事件正常触发。

注意通过[[UIApplication sharedApplication] setStatusBarOrientation:interfaceOrientation animated:YES];来设置屏幕旋转会导致

iOS version 8.1 ~ iOS version 8.3 之间的版本在横屏时出现home键后半部没有响应的情况。

对于点击事件会导致点击的坐标点不正确,但是对于滑动等手势不会造成影响,滑动拖动等手势一般都是根据相对位移来进行判断的。而点击事件大多都是根据绝对坐标进行判断的。

 如果因为使用[[UIApplication sharedApplication] setStatusBarOrientation:interfaceOrientation animated:YES]来旋转屏幕会出现iOS8.1-iOS8.3下出现home键后半部不响应点击事件的情况,而改用[[UIDevice currentDevice] setValue:rotation forKey:@"orientation"]来解决问题,就会出现顶部状态条不能跟随屏幕方向发送改变,另外对于键盘,声音大小的弹框等都不会更加设备的当前方向自动调整,就需要手动设置这些控件,特别是顶部状态条,在全屏下必须隐藏,这个可能会和设计的需求不一致。在iOS8.1-iOS8.3下解决不响应问题的方法为:

 重写hitTest方法将hitTest的坐标点转移到具有点击事件的视图上。


具体的内容可以看考demo:点击打开链接

关键部分为:

+ (BOOL)isNeedAdaptiveiOS8Rotation{
    NSArray<NSString *> *versionStrArr = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
    
    NSLog(@"versionArr is %@", versionStrArr);
    
    int firstVer = [[versionStrArr objectAtIndex:0] intValue];
    int secondVer = [[versionStrArr objectAtIndex:1] intValue];
    
    if (firstVer == 8) {
        if (secondVer >= 1 && secondVer <= 3) {
            return YES;
        }
    }
    
    return NO;
}

/**
 //对于iOS8.1 - iOS8.3版本使用
 [[UIApplication sharedApplication] setStatusBarOrientation:interfaceOrientation animated:YES];
 导致home键后半部点击区域不响应的解决办法。
 */
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    BOOL isNeedAdaptiveiOS8 = [[self class] isNeedAdaptiveiOS8Rotation];
    
    UIInterfaceOrientation currentInterfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
    
    //对于iOS8.1 - iOS8.3版本 当点击按钮位于home键的下半区域时不响应点击事件,因此只需要处理不响应的情况即可
    BOOL isNeedJudge = currentInterfaceOrientation == UIInterfaceOrientationLandscapeRight;
    
    if (isNeedAdaptiveiOS8 && isNeedJudge) {
        CGPoint btnPoint = [self convertPoint:point toView:self.clickBtn];
        if ([self.clickBtn pointInside:btnPoint withEvent:event]) {
            //点击区域在clickBtn上
            __weak typeof(self) weakSelf = self;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.11 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [weakSelf clickBtnAction:self.clickBtn];
            });
            weakSelf.userInteractionEnabled = NO;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                weakSelf.userInteractionEnabled = YES;
            });
            return self.clickBtn;
        }
    }
    
    return [super hitTest:point withEvent:event];
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值