Disable rotation animation of one subview - ios

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.

Related

Touch Event clicking UIImageView while rotating

My ImageView rotates but while it rotates it doesn't recognize touches on itself.
Do you think it's okay if I create a button via code that's over the ImageView that recognizes the touch?
When an animation is applied on any UIView or any subclass object of a UIView like UIImageView, UIButton etc then it does not detect touch events because when an animation is applied to a view, the animated property changes to its end value right away. what you are actually seeing on screen is the presentation layer of your views layer.
To answer your question, Yes, you can make a UIButton that covers up the area of the UIImageView to detect touch events on it. That sounds like the easiest to implement option in this case.
Apart from that, this link may also help you in the process. Hit testing animating layers

Use a UIView as the background of a UIButton?

I have a UIButton. Rather than giving it a background Image, I want to use a custom UIView object as the background. I realize I could do this by rendering the UIView into an image, then using that. But is there a better way?
I've looked at playing with the Button's view tree, but that seems to have undesirable side effects.
To achieve the same, I usually do this:
Add subview to the parentView
Add a UIButton with clearColor to the parentView, with the same frame as the subview.
You can achieve the same by creating a custom UIView class that has this view and button as its properties.
If you want to use a UIView as a button, you should just add a tap gesture recognizer to the UIView and use that. Is there something specific you're looking for?

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 subviews of window not rotating

I have a number of subviews on the main window. These subviews do not rotate. Is there an easy way to fix this problem?
Use UIViewController, it handles rotation automatically. There's rarely the need for adding subviews directly to the window.

Animating UIView center property not working on willRotateToInterfaceOrientation

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?

Resources