Tuesday 15 March 2011

animation - Animating view on UIKeyboardWillShowNotification event in iOS 8 -



animation - Animating view on UIKeyboardWillShowNotification event in iOS 8 -

i using next code animate view's position according keyboard movement. code works fine under ios 7, causes unusual behaviour under ios 8:

[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwillshow:) name:uikeyboardwillshownotification object:nil]; - (void) keyboardwillshow:(nsnotification*) anotification { nsdictionary* keyboardinfo = [anotification userinfo]; nstimeinterval time = [keyboardinfo[uikeyboardanimationdurationuserinfokey] doublevalue]; uiviewanimationcurve curve = [keyboardinfo[uikeyboardanimationcurveuserinfokey] intvalue]; cgrect keyboardframeend = [[keyboardinfo valueforkey:uikeyboardframeenduserinfokey] cgrectvalue]; double offset = keyboardframeend.size.width > keyboardframeend.size.height ? keyboardframeend.size.height : keyboardframeend.size.width; [uiview beginanimations:@"movewindow" context:nil]; [uiview setanimationbeginsfromcurrentstate:yes]; [uiview setanimationcurve:curve]; [uiview setanimationduration:time]; self.frame = cgrectmake(self.frame.origin.x, self.frame.origin.y + offset, self.frame.size.width, self.frame.size.height); [uiview commitanimations]; }

unfortunately, answers mentioned in is there alter behaviour of uikeyboardwillshownotification in ios 8? , ios8: what's going on moving views during keyboard transitions? out of question:

the source code base of operations big , old , utilize neither storyboard nor auto layout features. i don't want utilize uikeyboarddidshownotification event because keyboard visible , animation looks terrible (however, problem gone when using type of notification).

oddly enough, found out problem gone when feature used in first screen of application. farther tests showed removing mkmapview 1 of previous screens solves issue. triple checked mkmapview used , disposed correctly. every allocated instance gone way before above code executed.

after hours of testing , debugging noticed in visual hierarchy debugger (how inspect view hierarchy in ios?) there constraints added under uilayoutcontainerview , uinavigationtransitionview. these constraints not nowadays when mkmapview command removed previous screen. tried playing every possible combination of settranslatesautoresizingmaskintoconstraints: setup , not find resolution yet. sort of bug in ios 8 or there way animate view along keyboard?

i'm not sure code documentation animation methods...

use of method discouraged in ios 4.0 , later. should utilize block-based animation methods specify animations instead.

the right way animate view is...

[uiview animatewithduration:time delay:0 options:uiviewanimationoptionbeginfromcurrentstate animations:^{ self.frame = cgrectmake(self.frame.origin.x, self.frame.origin.y + offset, self.frame.size.width, self.frame.size.height); } completion:nil];

edit

ok, it's not autolayout (i think) i'll leave here anyway need alter , i'll wait more info in question.

ios animation notifications keyboard ios8

No comments:

Post a Comment