簡體   English   中英

IOS 8設置視圖幀不起作用

[英]IOS 8 set view frame not working

我有一個視圖,我想在顯示鍵盤時改變它的位置,我使用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]鍵盤顯示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 }}

我通過取消選中使用自動布局解決了我的問題。

如果您想要自動布局,這是另一種可能的解決方案:

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