I have a single UIView with some labels that display attributes from objects inside an array. I'm using gesture recognizers to change the current element in the array and hence the text in the labels. My question is how do I mimic a push animation without actually pushing a new view controller. Thanks for your help.
Thats simple way to use CGAffineTransformMakeTranslation to move any view from X axis to Y axis using UIViewAnimation. Before using this transition set your object frame to some x,y axis(0,0) and pass your x and y to move from.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
CGAffineTransform transform = CGAffineTransformMakeTranslation(x,y);
YOUR ViewOBJECT.transform=transform;
[UIView commitAnimations];
Have you tried to use the UIView class methods for animation? For example this could help:
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
In the animations block you could move one view out and another in.
Related
I am animating UIView when user touches on custom dropdown to show picker View from bottom side.UIView contains Pickerview...so when I change it's frame to move upwards.I get what I want, but pickerView doesn't recognize touch !(see screenshot below)
code is like this
CGRect pickerFrame=self.pickerSheet.frame;
CGRect viewFrame=self.view.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:SHEET_ANIMATION_DURATION];
//change Frame of View containing UIPickerView
pickerFrame.origin.y=202+animatedDistance;
viewFrame.origin.y-=animatedDistance;//animated distance is value by which view needs to move upward.
[self.pickerSheet setFrame:pickerFrame];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
screenshot
first of all, ++please**, stop using this animation declaration, and bedin use new, block animation:
[UIView animateWithDuration:SHEET_ANIMATION_DURATION
delay:0
options:nil
animations:^{
pickerFrame.origin.y=202+animatedDistance;
viewFrame.origin.y-=animatedDistance;
}
completion:^(BOO f){
//any actions after animation ended
}];
Second, I think your problem is somewhere else. May by, you implementing your touches or picker wrong.
Please start using the new , better animation block , but I think there is something missing in your code , you need to put the code below :
UIViewAnimationOptionAllowUserInteraction
Put this code in options in the new animation block , or find a way to put it in the old animation block
Im using CGAffineTransformMakeScale to scale a UIView from 0.1 to 1.0.
The problem is that the view is also rotating while the scaling is being animated. So it ends with a scale of 1.0 AND 90ยบ of rotation.
[self presentModalViewController:slideTwoViewController animated: NO];
[slideTwoViewController.view setTransform:CGAffineTransformMakeScale(0.1,0.1)];
[UIView beginAnimations: nil context: nil];
[UIView setAnimationDuration:2.0];
[slideTwoViewController.view setTransform:CGAffineTransformMakeScale(1.0,1.0)];
[UIView commitAnimations];
The initial application orientation is landscape left. So when the animation ends the UIView looks like in portrait.
Is this supposed to happen? am I missing something?
Thanks
My bet, is the view already have a transform set and you are overwriting it with the new transform and it is animating the difference.
Try using the following function instead:
CGAffineTransformScale(<#CGAffineTransform t#>, <#CGFloat sx#>, <#CGFloat sy#>)
With this function, you pass the original transform slideTwoViewController.view.transform and your scale factor.
slideTwoViewController.view.transform = CGAffineTransformScale(slideTwoViewController.view.transform, 0.1, 0.1);
Despite of scaling rootview try to add subview which become your new pseudo rootview (with all the rest subviews connected underneath) and then scale pseudo rootview. This way you are avoiding any transform collisions made by system on the real rootview (e.g. autorotating) and then you can use CGAffineTransformMakeScale freely.
I would like to animate a curtain, which gets opened. I have two images: one for the left and one for the right side of the curtain (depicted in red). I would like to smoothly slide them away with Core Animation. For what animation type should I look for? How do I achieve a realistic sliding style?
Regards,
Stefan
alt text http://img.skitch.com/20100627-8ytxrbe64ccbruj49c2pbs7kt2.png
I'm not sure why people are suggesting using a translation. If all you need to do is slide the images, simply call -setCenter on each image view inside an animation block. Like this:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[leftCurtainImageView setCenter:pointOffScreenLeft];
[rightCurtainImageView setCenter:pointOffScreenRight];
[UIView commitAnimations];
Where pointOffScreenLeft, and pointOffScreenRight are calculated something like:
CGPoint pointOffScreenLeft = CGPointMake(
-[leftCurtainImageView bounds].size.width,
[leftCurtainImageView frame].origin.y);
CGPoint pointOffScreenRight = CGPointMake(
[rightCurtainImageView frame].origin.x +
[rightCurtainImageView bounds].size.width,
[leftCurtainImageView frame].origin.y);
These calculations assume that the curtains are positioned at the far left and far right edges respectively of their containing view.
The easiest solution would be to have to imageview or CGLayers and then use CGAffineTransformTranslate in an animation block to slide them off screen.
Man
After a long search. The only way I could find is this.
https://github.com/Ciechan/BCMeshTransformView
I have a UIView called goalBar which is being animated by increasing the size of the frame according to a float value called destination:
CGRect goalBarRect = CGRectMake(0, 0, destination, 29);
[UIView beginAnimations:#"goal" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2.0f];
goalBar.frame = goalBarRect;
[UIView commitAnimations];
The animation works perfectly and the rectangular view increases its width over the course of the animation (from 0 to the value for destination).
However, I wish to be able to extract the values for the frame of the UIView being animated (i.e. goalBar) as the animation takes place. By that I mean that I wish to place the value of the width for the animated frame in a separate UILabel so that the user sees a counter that provides the width of the UIView as it's being animated.
Any help on how to do the above would be gratefully received.
How about observing the frame property of the view. So that you get callbacks when it changes.
See Key-Value Observing.
I've looked into this and it seems that it is not possible to get updates on the state of the components being animated during the UIView animation process.
Before I go into doing everything by hand I would like to ask if there is some help to get from the framework.
I have a UIView that holds another UIView with a map. The parent UIView holds some legends for the map. Initially I define some coordinates in the map view. e.g. (100, 40), and place a piece of graphics there in the parent view (like a tack in google maps etc.). The parent view and the child view are both 300x200 and have the same origin. This means that (100, 40) is the same point in both views.
Now I zoom and move the child UIView(the map) using CGAffineTransform and the coordinate (100, 40) is now situated somewhere else. The parent view is effectively a mask here.
Can I use the CGAffineTransform Matrix or another part of the framework to calculate and inform the parent view where to place the tack now that the point has moved?
i.e. (100, 400) in the child view compared to (100, 40) in the parent view, what does it compare to after the transformation?
Thank you for suggestions or help given.
The animation of the child UIView
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
CGAffineTransform transform = CGAffineTransformMakeScale(1.8f, 1.8f);
worldMap.transform = transform;
worldMap.bounds.origin = newPos;
[UIView commitAnimations];
UIView's -convertPoint:toView: and -convertPoint:fromView: should work for you.