ios - UIView animation returns to origin -



ios - UIView animation returns to origin -

i have uilabel within of uitableviewcell. trying animate label moving right when user taps cell. have code:

cgrect otherframe = celllabel.frame; otherframe.origin.x +=50; [uiview animatewithduration:1.0f animations:^{ celllabel.frame = otherframe; }];

the odd thing that's happening label jumping 50 pixels left , animating origin (where before action began).

i had working before in week , didn't have problem it, , after scouring through revision history, can't figure out i've gone wrong. must missing stupid.

edit: based on reply jakub, found works:

[uiview animatewithduration:0.01f animations:^{} completion:^(bool finished) { cgrect otherframe = celllabel.frame; otherframe.origin.x += 50; [uiview animatewithduration:1.0f animations:^{ celllabel.frame = otherframe; }]; }];

oddly, if move of logic completion handler performs new animation after first 1 completes (without first doing anything), animates properly. super hacky, , i'm not @ happy it.

can think of cause initial animation move frame negative offset of intended destination, animate origin, , why triggering new animation completion handler of empty animation work?

edit 2:

i going mark duncan's reply right 1 because pointed me in right direction, still baffled why/how these symptoms can happen:

the animation moves frame negative offset of destination, animates origin (rather origin destination) running empty animation block adding animation first block's completion handler animates correctly

info attempted answers:

i have utilize auto layout project, , far know, can't disable single view i not putting onto background thread. didn't seek dispatching main thread, think there. isn't visible ui on main thread? animating, not expected. the reason didn't go route of changing constraints begin using prototype cells , ib doesn't allow create iboutlets prototype cells. there's bit of work walk constraint list , observe specific one, left constraints blank , tried animate frame (and said, working before in week -- , still worked when animating animation block's completion handler).

so final solution add together constraints container cell (the of import 1 here beingness leading), animate, had find constraint:

nslayoutconstraint *titleleadingconstraint = nil; for( nslayoutconstraint *constraint in celllabel.superview.constraints ) { if( constraint.firstitem == celllabel && constraint.firstattribute == nslayoutattributeleading ) { titleleadingconstraint = constraint; } }

then set constraint constant:

titleleadingconstraint.constant = 55.0;

then set animation block:

[uiview animatewithduration:1.0f animations:^{ [self.view layoutifneeded]; }];

this solution should more future proof (and robust, reliable , stable) moving frame, turned out fair amount of work in discovery.

do have auto layout set in storyboard or xib mistake? (it on default). if either need turn autolayout off or animate constraint rather manipulating view's frame.

ios objective-c

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -