XFDialogBuilder icon indicating copy to clipboard operation
XFDialogBuilder copied to clipboard

楼主你是如何兼容IOS7下横屏的,貌似会显示旋转逆时针90度的。你是怎么解决这个问题的?

Open jaccty opened this issue 8 years ago • 1 comments

楼主你是如何兼容IOS7下横屏的,貌似会显示旋转逆时针90度的。你是怎么解决这个问题的?核心代码是?

jaccty avatar Jul 20 '16 06:07 jaccty

有两种解决方案:

第一种,使用侦听通知,在顶级视图添加代码

  // 侦听屏幕旋转
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotateWithNoti:) name:UIDeviceOrientationDidChangeNotification object:nil];

- (void)willRotateWithNoti:(NSNotification *)noti {
    [UIView animateWithDuration:0.25 animations:^{
        self.frame = CGRectMake(0, 0, ScreenSize.width, ScreenSize.height);
    }];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    // 重新布局对话框视图
    self.dialogView.centerX = self.centerX;
    self.dialogView.centerY = self.centerY;
    [self.dialogView layoutIfNeeded];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

第二种方式,AutoLayout(简单,推荐使用),同样在顶级视图添加代码

self.translatesAutoresizingMaskIntoConstraints = NO;
    NSArray *hConstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[maskView]-0-|" options:0 metrics:nil views:@{@"maskView":self}];
    [self.frontWindow addConstraints:hConstraint];
    NSArray *vConstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[maskView]-0-|" options:0 metrics:nil views:@{@"maskView":self}];
    [self.frontWindow addConstraints:vConstraint];

// 然后再布局,这是必写的
- (void)layoutSubviews
{
    [super layoutSubviews];
    // 重新布局对话框视图
    self.dialogView.centerX = self.centerX;
    self.dialogView.centerY = self.centerY;
    [self.dialogView layoutIfNeeded];
}

可以参考本项目的XFMaskView类,如有对你帮助,可以Star

yizzuide avatar Jul 20 '16 10:07 yizzuide