No rotation and scaling for subviews - iphone

I have one UIView with slider and segment control as a subview.
I am using gesture control to handle rotation and scalling. Now while rotating uiview, the slider and segment control also get rotated.
I dont want rotation and scaling for subviews.
Please help me to sort this issue.
Thanks

Don't have your segmented control and slider as subviews of the scaled view.
If necessary, you could have a containing superview that contains the scaled view, segmented control and slider as subviews.

You could "counter-rotate" your subviews when you handle the gesture for rotating the UIView.
Create a CGAffineTransformRotate and apply it to your subview in case you do not want it to rotate:
[UIView beginAnimations:nil context:nil];
CGAffineTransform transform = CGAffineTransformRotate(subview.transform, radians);
subview.transform = transform;
[UIView commitAnimations];
After you apply the transformation to the subviews, they will be rotated accordingly until you reset the transformation to its default value.

Related

iPhone How to get photo taken effect like in camera application?

I am talking about that effect when user presses button to take photo, it shrinks and moves to toolbar? How is this achieved in general?
You can create this by both scaling (applying a transform) and moving (animating the position) of the image.
I wrote about a similar animation (the Open in Background animation from Safari on iPhone) in this blog post. Not all of the code is necessary but some part of it will be useful for the animation you are trying to do.
You should
Calculate the scale factor to make the image the appropriate size
Calculate the path you want to animate the image along.
Animate a scale with the calculated scale factor
Animate a position animation along the path (using a CAKeyframeAnimation)
Since you are doing two animations at once you could benefit from using a CAAnimationGroup.
Since you are animating down to a toolbar which probably is another part of the view hierarchy than where the image is you may need to use method like
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view
and
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view
To translate coordinates between the different views.
so the shrink animation is achived by
[UIView beginAnimations:#"animationShrink" context:NULL];
[UIView setAnimationDuration:kSlideInAnimationDuration];
flipFlopContainer.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(shrinkAnimationFinished:)];
[UIView commitAnimations];
after this animation in shrinkAnimationFinished method you need to define a path to follow and change the position of your view accroding to that path.
See the following thread for that animation
Resize and move a UIView with Core Animation (CAKeyFrameAnimation)

clipping a UIView while zooming in

I have a custom UIView that draws some data and another more detailed view that draws some components of the first view. What I want to do is after a gesture, zoom in, hide the first view, and then show the second view to give the user the context that they are zooming in deeper.
I thought I would start by doing something like this:
CGAffineTransform zoomTransform = CGAffineTransformMakeScale(2, 2);
[UIView animateWithDuration:2 animations:^{
self.chromoMap.transform = zoomTransform;
}];
It does zoom in on that area by scaling that UIView. However, I don't want my UIView to actually grow. If my CGRect is {0, 0}, {100, 100}. I want the frame of the UIView to stay the same, but just the contents inside it to scale by 2 to give that zoom effect. How would I do that? Thanks.
It seems I can just add another transparent UIView on top of it with clip subviews enabled to get that effect.

Infinite rotating image background UIImageView

I'd like to extend a class from UIImageView,which will infinite rotate a universe image. So I can simply put this image view as background view for other UI elements.
3 questions here:
Is it the right way to extend from UIImageview class.
How to keep rotating infinite, and as background, when put it into other views, I don't need to write extra lines of code.
I wrote a rough prototype, when I put it into other views as background, all UI elements in this view are rotating with the image.
Assume that you have a UIImageView and assign an image on it and named myImgView. On viewDidLoad, add your code as bellow:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationRepeatCount:MAXFLOAT];
myImgView.transform = CGAffineTransformMakeRotation(M_PI);
[UIView commitAnimations];
It works for me like a charm.
There is nothing wrong in extending UIImageview Class.
Create rotation animation and set repeat ON.
Do not add element on rotating image. (Add elements in base view. Insert rotating imageview at index 0).
From the UIView Class Reference:
The UIImageView class is optimized to draw its images to the display. UIImageView will not call drawRect: a subclass. If your subclass needs custom drawing code, it is recommended you use UIView as the base class.
At present, UIImageView subclasses do work, especially if they don't interfere with the drawing code. Just don't complain to apple if a future iOS update breaks your subclass. It's easy enough to write your own UIView subclass to display an image. If you already have an appropriate graphics, consider just placing it in CALayer contents, instead of implementing the UIView drawRect method.
Rotations by changing UIView transform (which is of type CGAffineTransform) always take the shortest path. This means that a clockwise rotation of 270 degrees is animated as an anticlockwise rotation of 90 degrees, and any multiple of 360 degrees will do nothing. You can get 360 degree rotations if you obtain the view's layer, and animate CALayer transform (which is of type CATransform3D). See Can I use CGAffineTransformMakeRotation to rotate a view more than 360 degrees?
To make the animation repeat endlessly, the CAMediaTiming Protocol Reference recommends setting repeatCount to HUGE_VALF.

iphone - Strang behavior when I set a UIImageView's frame while is in CGAffineTransformMakeScale animation

I have a UIImageView showing an image with the contentMode of UIViewContentModeScaleAspectFill.
Then I am associating a animation (about 30 seconds) of CGAffineTransformMakeScale with the UIImageView.
imageView.transform = CGAffineTransformMakeScale(1,1);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:30];
imageView.transform = CGAffineTransformMakeScale(1.9,1.9);
[UIView commitAnimations];
After 30 seconds, when a round of animation is done, I will set another image to the imageView and restart the animation.
Everything is fine. But when I try to rotate the UIImageView to adapt user's selection of device orientation, it becomes wired.
When the user is about to change the orientation, I set the UIImageView's frame to CGRectMake(0, 0, 768, 1004) or CGRectMake (0, 0, 1024, 748), accordingly.
The strange thing is:
if the frame of UIImageView is changed while the animation, it is fine. But when the next image comes and starts a new round of animation, the UIImageView suddenly became small in the center of screen (is supposed to be full screen) and then the animation of zoom-in started as usual, just not full screen any more.
Can anyone tell me how to control the frame or orientation while the UIImageView has a transform with it?
Because I guess this is where it went wrong.
Thanks
Quoth the documentation for the frame property:
Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.
You should probably be messing with center and bounds instead, if you are using transformations.
Frame property is not defined when transforming. Use bounds instead of frame in this case.

UIImageView Zoom in and out

I want to change the images depending upon the zoom in or zoom out.
Means if i am zoom upto certain limit then it should show other image.
I added one UIImageView in UIScrollView and zoom in and out functionality is working but i am not getting how to change image during zoom in and zoom out.
And while changing image it should have fade effect in between.
Can any one help me for this?
UIScrollViewDelegate has a method - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale.
In this method you can check the scale and update the UIImageView with the appropriate UIImage.
For animating an image change, you can do:
[UIView beginAnimations:#"imageChange" context:NULL];
yourImageView.image = yourNewImage;
[UIView commitAnimations];
The change will have the fade effect you want.
About the zoom-in and zoom-out functionality I'm not sure, but you should check if the view is zooming (zooming property for your UIScrollView should be true) and then use the zoomScale property. I suppose you could do this with a timer, continuously checking if the view is zooming.