IOS 8设置视图帧不起作用

我有一个视图,我想在键盘显示时改变它的位置,我使用UIKeyboardWillShowNotification委托来更新位置,它在 IOS 7设备中完美运行但是当我尝试在IOS 8设备中运行它时,视图没有重新定位,框架更新,因为我可以在日志中看到它.

以下是我的代码

-(void) keyboardWillShow:(NSNotification*) notification{

    @autoreleasepool {
        CGRect frame = _loginFrame.frame;
        frame.origin.y-=200;

        DLog(@"login frame %@ ",NSStringFromCGRect(frame));
        [UIView animateWithDuration:0.25 animations:^{
            [_loginFrame setFrame:frame];
        }];
    }

}

但是,当我在dispatch_after中尝试动画时阻止其动画到新位置

dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(0.2 * NSEC_PER_SEC)),dispatch_get_main_queue(),^{
    [UIView animateWithDuration:0.25 animations:^{
        [_loginFrame setFrame:frame];
    }];
});

知道为什么没有dispatch_after框架没有动画到新位置?

谢谢!

注意:它看起来像setFrame:方法不起作用,不知道为什么,我已经创建了一个基本的ios 8应用程序来测试这个

2014-09-11 18:59:54.836 KeyboardCheck[31215:1451974] keyboard show
2014-09-11 18:59:54.837 KeyboardCheck[31215:1451974] old frame
{{60,269},{200,30}}
2014-09-11 18:59:54.837
KeyboardCheck[31215:1451974] update frame {{60,169},30}}
2014-09-11 18:59:55.339 KeyboardCheck[31215:1451974] completion
block frame {{60,30}}
2014-09-11 18:59:55.822
KeyboardCheck[31215:1451974] keyboard hide 2014-09-11 18:59:55.822
KeyboardCheck[31215:1451974] old frame {{60,30}}
2014-09-11 18:59:56.324 KeyboardCheck[31215:1451974] completion
block frame {{60,30}}

解决方法

我通过取消选中使用自动布局解决了我的问题.

如果您想要自动布局,这是另一种可能的解决方案:

https://teamtreehouse.com/forum/animating-views-does-not-seem-to-work-in-ios8-but-did-in-ios7

以上是来客网为你收集整理的IOS 8设置视图帧不起作用全部内容,希望文章能够帮你解决IOS 8设置视图帧不起作用所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。