简体   繁体   English

IOS 8设置视图帧不起作用

[英]IOS 8 set view frame not working

i have a view which i want to shift its position when keyboard is shown, i use UIKeyboardWillShowNotification delegate to update the position, and its working perfectly in IOS 7 device but when i try to run it in IOS 8 device, then view is not repositioned , the frame is updated as i can see it in log. 我有一个视图,我想在显示键盘时改变它的位置,我使用UIKeyboardWillShowNotification委托来更新位置,它在IOS 7设备中完美运行但是当我尝试在IOS 8设备中运行它时,视图没有重新定位 ,框架更新,因为我可以在日志中看到它。

following is my code 以下是我的代码

-(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];
        }];
    }

} }

But, when i try the animation in dispatch_after block its animating to the new position 但是,当我在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];
    }];
});

any idea why the frame is not animating to the new position without dispatch_after ? 知道为什么没有dispatch_after框架没有动画到新位置?

Thanks! 谢谢!

NOTE: it looks like the setFrame: method is not working , dont know why, i have created a basic ios 8 application to test this 注意: 它看起来像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}, {200, 30}} 2014-09-11 18:59:55.339 KeyboardCheck[31215:1451974] completion block frame {{60, 269}, {200, 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, 269}, {200, 30}} 2014-09-11 18:59:56.324 KeyboardCheck[31215:1451974] completion block frame {{60, 269}, {200, 30}} 2014-09-11 18:59:54.836 KeyboardCheck [31215:1451974]键盘显示2014-09-11 18:59:54.837 KeyboardCheck [31215:1451974] 旧框架{{ 60,269 },{ 200,30 }} 2014 -09-11 18:59:54.837 KeyboardCheck [31215:1451974] 更新帧{{ 60,169 },{ 200,30 }} 2014-09-11 18:59:55.339 KeyboardCheck [31215:1451974] 完成块帧{ { 60,269 },{ 200,30 }} 2014-09-11 18:59:55.822 KeyboardCheck [31215:1451974]键盘隐藏2014-09-11 18:59:55.822 KeyboardCheck [31215:1451974] 旧框架{{ 60,269 },{ 200,30 }} 2014-09-11 18:59:56.324 KeyboardCheck [31215:1451974] 完成块框{{ 60,269 },{ 200,30 }}

I solved my problem by unchecking Use Auto Layout. 我通过取消选中使用自动布局解决了我的问题。

If you want Auto Layout, here is another possible solution: 如果您想要自动布局,这是另一种可能的解决方案:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM