Animating UIView center property not working on willRotateToInterfaceOrientation - ios

I'm animating a subview in the UIViewController's willRotateToInterfaceOrientation. First, I was setting its frame to a new position and it was working fine. Since I just animate the positioning I tried to animate the center property instead. As soon as I do it, the animations do not work anymore.
I'm using UIView's animateWithDuration and when checking the completion block, the finished parameter is always NO. Animating the center property on other events like a button click works fine.
Might it be that the rotation algorithm iOS uses to reposition a view's subviews also touches the center property and cancel's my animation?

Related

Disable rotation animation of one subview

I'm trying to disable device orientation animation for just some subviews in my UIView subclass. I managed to disable camera preview rotation animation by using this view layer as AVCaptureVideoPreviewLayer and reacting to UIApplicationWillChangeStatusBarOrientation by changing layer.connection.videoOrientation. This works ok, but I also have one subview added that I also want to rotate without animation. Is there some way I can remove this animation for just that subview? Also I can't use willAnimateRotationToInterfaceOrientation as it's in UIViewController, and I want my UIView subclass to work this way without implementing anything additional in the controller. I only have UIView functions and NotificationCenter to work with.

How can I maintain relative scrolling position within a UIScrollView during a UISnapBehavior animation?

I am using a UIDynamicAnimator's UISnapBehavior to animate these circles between two states:
http://cl.ly/image/1G3p1B2x2v14/Image%202013.09.24%2011%3A35%3A43%20AM.png
That works great. However, I then put this inside a UIScrollView. When I scroll before the UISnapBehavior animation has "settled" (there seems to be a delay after it looks like it finishes and when it actually finishes), the circles lose their relative positioning to the scroll container:
http://cl.ly/image/1E0I3l460J1V/Image%202013.09.24%2011%3A32%3A10%20AM.png
When I scroll after waiting a few seconds after the animation has "settled", the circles do not lose their relative positioning
I'm assuming this is because UISnapBehavior animates things with fixed positions, and then reverts back to relative positioning after it finishes, but I'm not sure if that's true.
I was setting the UIDynamicAnimator on a UIView containing the UIScrollView. Setting the UIDynamicAnimator initWithTarget to the UIScrollView seems to have fixed it.
Try putting your circles within a UIView that's a subview of a UIScrollView instead of in the scroll view itself. I've seen it do some weird things before.

Moving UIView and subviews periodically

I am building a word tetris kind of an app. Now I have to move a Uiview containing 8 uibuttons towards the bottom of the screen based on time and also track the position of uibuttons as the user taps specified button.
Am I suppose to use Block based animation or core animation to do the task.
Currently if I am animating frame and center of superview it seems like I have to do the same for the subviews as well inside the block.
Any input would be handy.
You can use UIView block animation to animate a view and it's subviews quite simply.
However, neither UIView animation nor core animation will let the user click on buttons as they are animating. Button actions don't work at all on "in flight" animations. There's no automatic way to do that. (At least none that I know of.)
Instead, you have to add a tap gesture recognizer to the parent view, and do hit testing on the presentation layer of your parent view to see which sublayer of the presentation layer is tapped.

iOS - Positioning of a running animation on orientation change

I have applied a CABasicAnimation to a layer. The animation modifies the "position.y" layer property to create a gentle bouncing effect; it is set to autoreverse and repeat.
I use the From and To values to position the animation in the bottom right quadrant of the screen. It works quite nicely until I change the orientation of the device. The problem is the animation is positioned relative to the top of the screen. So when the orientation changes it is no longer positioned in the correct place.
The autoresizingMask for the View itself is correctly set in interface builder, but the animation doesn't seem to take any notice of that. I guess because the animation is assigning an absolute value to the layers position.
I'm a bit stumped, thanks in advance.
Can you place your animation in a seperate view so it is self contained and then adjust that view with the rotation?

How to delay flipping a UIView containing an updating UIButton having a gradient background

I have two views that flip based on a button press within the view. The view has two CAGradientLayers as sublayers. If I flip immediately after the action method fires, the button is in the process of changing the opacity of the gradients and so you see stuttering (the UIVIew flip animation is having to accommodate the button that is itself changing.)
I can hack a solution by doing a performWithSelection:withObject:afterDelay:0.1f, but it feels like such a hack. I tried setting the layer's needsDisplay property and testing for when it was clears, but probably this is insufficient to tell me the screen itself has redrawn.
Dav
In the end this has no solution. I have since found that when animating a view there are severe performance implication if you also try to animate the super views. You can see this in many iOS apps where the app animates an image in a scrolling list - the scrolling stumbles.
So what I learned is either animate something, or it's view, but not both!

Resources