ios - Animating a UIButton to fullscreen -
so have simple button when clicked goes fullscreen , when clicked again goes same position in. reason works without animation. when uncomment animation part when click button nothing, second time click enlarges. third time click animates it's smaller original size... why animating opposite way?
- (ibaction)viewimage1:(id)sender { uibutton *btn = (uibutton*) sender; if (btn.tag == 0) { cgrect r = [[uiscreen mainscreen] bounds]; /*[uiview animatewithduration:0.5f delay:0.0f options:0 animations:^{*/ [sender setframe: r]; /*}completion:nil];*/ btn.tag = 1; } else { btn.tag = 0; [sender setframe:cgrectmake(0,0,370,200)]; } }
there 2 solutions problem either of work:
disable autolayout. (discouraged)
can in interface builder opening file inspector
in right pane , unchecking respective check box.

however, if want use autolayout constraining other ui elements in view (which quite idea in cases) approach won't work why recommend second solution:keep autolayout enabled, create outlet button in view controller , set
self.mybutton.translatesautoresizingmaskintoconstraints = yes;in view controller's
viewdidloadmethod.you add layout constraints button , animate those. (this excellent stackoverflow post explains how it's done.)
the reason tricky behavior once enable autolayout view's frame no longer relevant actual layout appears on screen, view's layout constraints matter. setting translatesautoresizingmaskintoconstraints property yes causes system automatically create layout constraints view "emulate" frame set, in manner of speaking.
Comments
Post a Comment