Is there a way to determine how far a UIView has been rotated in Swift? For example, the UIView is rotated by the user using a rotation gesture recognizer, and then later, outside the gesture recognizer callback function, I want to determine how many degrees (or radians) the UIView was rotated.
I think it can be done using CGRectGetMinX, CGRectGetMaxX, CGRectGetMinY and CGRectGetMaxY but is there a simpler way to do it?
atan2(view.transform.b, view.transform.a) should do the trick if the UIView was not skewed.
Related
I want to build an App that enables you to draw in an image, while zooming in.
I have a working code that lets you draw into an image, but the problem is that I also want to zoom in. I need to find a way to zoom and move around with 2 Fingers and draw with 1 Finger.
I tried:
self.scrollView.panGestureRecognizer.minimumNumberOfTouches = 2;
But the problem is that this disables the drawing.
I also tried to add an UIPanGestureRegognizer but that won't fit in the framework I prefer to use.
So I am asking for a way to make scrollView ignoring the 1 Finger gesture or a drawing Framework that supports zooming.
Set your UIViewController (or UIView, whatever you use for showing) as delegate for your recognizers. Then add gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: and return YES for your case or always if you don't have another recognizers.
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.
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
I have a UIButton and a UIView that belong to two different views hierarchies and I'm trying to detect a collision when I drag my button to the “viewTrashArea”.
The problem is that the frame of the button and the frame of the view are in different coordinates and therefore make the collision think that they are touching but they are far away from each others.
How can I detect the collision based on the global screen position?
Given
UIButton *button;
UIView *viewTrashArea;
This line would return true if they intersect:
CGRectIntersectsRect([button convertRect:button.bounds toView:viewTrashArea], viewTrashArea.bounds);
You'll need to convert the positions to a common coordinate system. Use the UIView methods convertRect:fromView: and convertRect:toView: for this purpose.
I have a UIImageView whose instance has a repeating pulse-like animation.
I want this UIImageView to move with the force of the accelerometer. To do this I have added another animation, this time a translation.
However, once this translation happens, it stops the pulse, even when its not animating.
As these two animations are separate, I cannot use the CGAffineTransformConcat method to combine both animations.
I have tried adding one to the UIView and one to the layer property of the same UIView but it does not work.
I have also tried adding the movement directly to the frame of the view, however, this just causes my view to disobey the constraint constraining it to the center x of the superview.
Does anyone use/know of a work around to this?
Thanks as always!