Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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_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 ?

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

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}}

like image 355
Ramesh Lingappa Avatar asked Oct 20 '22 01:10

Ramesh Lingappa


1 Answers

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

like image 171
vonlost Avatar answered Oct 22 '22 20:10

vonlost