UIView Animation Mac OSX Effect - uiview

I'm animating a small view with popup effect to alert you of an error ... The animation works perfectly but still are not very satisfied because I would like the view does not stop at position (x 25) but I wish they came to ( x 40 ) and then return immediately to ( x 25). In other words I would like to recreate the effect they have on the textfield MontainLion when you are wrong to insert the fields User for access to the operating system ...
I really hope to be able to explain to me , but if I did not succeed please comunicarmelo so that I can explain it better to resolve this question. Thanks to all! Rory .
Below I show you the code to display the pop-up I'm using
- (Void)presentazioneViewTransition
{
CGRect endREct ;
endREct = CGRectMake (25, 160, 270, 90);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(endRightAnimation)];
self.frame = endREct;
[UIView commitAnimations];
}

You can use the simple block based UIView animation methods like this
-(void)presentazioneViewTransition{
CGRect transitionRect = CGRectMake(40.0f, 160.0f, 270.0f, 90.0f);
CGRect endREct = CGRectMake (25.0f, 160.0f, 270.0f, 90.0f) ;
[UIView animateWithDuration:0.15f
animations:^{
self.frame = transitionRect;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:0.1f
animations:^{
self.frame = endREct;
}];
}];
}

Related

Slow down UIView animation like as the dropdown Menu in iOS

I have a problem with animation show UIView slow down like as dropdown menu. I tried below code but it so fast.
Can you help me to correct it? Thanks.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
blockView.frame = CGRectMake(newFrame.origin.x, newFrame.origin.y , newFrame.size.width, newFrame.size.height + *h);
[blockView addSubview:dropDownView];
[UIView commitAnimations];
I want to make UIView slow down like as the Expedia app. Please give me some advice.
Thanks in advance.
Just increase the AnimationDuration based on how much slow u want to make your drop down.
Exmaple:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.5];
self.blackView.frame = CGRectMake(newFrame.origin.x, newFrame.origin.y , newFrame.size.width, newFrame.size.height + h);
[self.blackView addSubview:self.dropDownView];
[UIView commitAnimations]
if u feel your dropDownView attached before the animation gets complete means u can use following code to attach your dropDownView at end of the animation completion.
[UIView animateWithDuration:5.5
animations:^{
self.blackView.frame = CGRectMake(newFrame.origin.x, newFrame.origin.y , newFrame.size.width, newFrame.size.height + h);
}
completion:^(BOOL finished){
[self.blackView addSubview:self.dropDownView];
}];
Use the options in UIView animation
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
// ... do stuff here
} completion:NULL];

Resize an image but never came back to original size

I'm trying to resize an image (tiny and return to original size). This code is working for resize the image but never go back to the original size. I thin I miss something in the endItem1Animation code. Any suggestions? Thanks
if (CGRectIntersectsRect(image.frame, item1.frame)) {
item1.hidden = YES;
// Item 1 Animation (Go Tiny)
[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationsEnabled:YES];
[UIView setAnimationDelay:0];
[UIView setAnimationDuration:0];
[UIView setAnimationRepeatCount:0];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationRepeatAutoreverses:NO];
CGRect newRect = image.frame;
newRect.size = CGSizeMake(25,25);
image.frame = newRect;
[UIView commitAnimations];
[self endItem1Animation];
This is the endItem1Animation code:
// Item 1 End Animation (Return to Original Size)
[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationsEnabled:YES];
[UIView setAnimationDelay:0];
[UIView setAnimationDuration:5.0];
[UIView setAnimationRepeatCount:0];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationRepeatAutoreverses:NO];
CGRect newRect = image.frame;
newRect.size = CGSizeMake(50,50);
image.frame = newRect;
[UIView commitAnimations];
The problem is that when you call beginAnimations / endAnimation, this does not block the main thread from running, so calling [self endItem1Animation] sets the second animation which will prevent the first animation from running.
You'll want to use the UIView animation block method instead, which lets you supply a completion handler when the animation completes.
[UIView animateWithDuration:0.5 animations:^{
CGRect newRect = image.frame;
newRect.size = CGSizeMake(25,25);
image.frame = newRect;
} completion:^(BOOL finished) {
[self endItem1Animation];
}];
Another, more straightforward issue, is that the duration for the first animation is zero.
I fix this issue running a selector at the end of the code. Now my code is working. Here is my final code, I Hope to help someone. Thank you for your suggestions.
if (CGRectIntersectsRect(image.frame, item1.frame)) {
item1.hidden = YES;
// Item 1 Animation (Go Tiny)
[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationsEnabled:YES];
[UIView setAnimationDelay:0];
[UIView setAnimationDuration:0];
[UIView setAnimationRepeatCount:0];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationRepeatAutoreverses:NO];
CGRect newRect = image.frame;
newRect.size = CGSizeMake(25,25);
image.frame = newRect;
[UIView commitAnimations];
[self performSelector:#selector(endItem1Animation) withObject:nil afterDelay:8.0];

animateWithDuration:delay:options:animations:completion: not working (strangely)

I'm trying to translate a UIView for a distance using the following code:
CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100);
[self.exposureHintView setTransform:transform];
[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
NSLog(#"Begin!");
CGAffineTransform newTrans = CGAffineTransformMakeTranslation(0, 0);
[self.exposureHintView setTransform:newTrans];
}
completion:^(BOOL finished) {
NSLog(#"End %d", finished);
}];
So basically, I'm justing trying to move the view from some point say (-100, -100) to where it should be (0, 0) relative to itself.
Since I wanted to animate it once the view appeared, so I put the code in viewDidAppear:. But when I run the code, nothing happened.
The self.exposureHintView here is a custom subclass of UIView, does it matter?
Why?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[_AboutView setFrame:CGRectMake(0, 0, 320, 510)];
[UIView commitAnimations];
Use this code to change the position of your view
I think the problem here is you are create exposureHintView in storyboard or XIB file without code programmatically.
Try to do as the follows:
- (void)viewDidLoad
{
//Init exposureHintView
UIView* exposureHintView = [[UIView alloc]initWithFrame(sampleFrame)];
[self addSubView: exposureHintView];
//Set transform
CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100);
[self.exposureHintView setTransform:transform];
//Commit animation
[UIView animateWithDuration:2.0 delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
NSLog(#"Begin!");
CGAffineTransform newTrans = CGAffineTransformMakeTranslation(0, 0);
[self.exposureHintView setTransform:newTrans];
}
completion:^(BOOL finished) {
NSLog(#"End %d", finished);
}];
The reason here is your could not set Frame or Transform or some another attribute of this UIView in >>ViewDidLoad when you using storyboard or XIB

zoom animation using animation with block based methods

I have a zoom animation in which when I perform an action, a view comes up in a zooming fashion.
The code I use to do this is,
CGFloat xpos = self.view.frame.origin.x;
CGFloat ypos = self.view.frame.origin.y;
popContents.view.frame = CGRectMake(xpos+100,ypos+150,5,5);
[UIView beginAnimations:#"Zoom" context:NULL];
[UIView setAnimationDuration:0.8];
popContents.view.frame = CGRectMake(320, ypos-70, 350, 350);
[UIView commitAnimations];
[self.view.superview addSubview:popContents.view];
I just realized that in ios4.0 usage in this fashion is not recommended and animations using block based methods is recommended..
I tried looking for any sort of example which would give me a hint to get the zooming effect I need using the block based methods but I have not been able to find any...
It would be great if anyone could help me out in this...
i figured it out...
Apparently "zoom" is just a name and does not do anything( as far as I experimented with it)
Here is how I achieve the effect using animate with block based methods...
[UIView animateWithDuration:0.8 animations:^ { popContents.view.frame = CGRectMake(160, 70, 350, 350);
[self.view.superview bringSubviewToFront:self.view];
[self.view.superview addSubview:popContents.view]; }
completion: ^(BOOL finished) {
NSLog(#"DONE");
}
];
Now there is just 1 issue I am not able to figure out..
Here is the edited code -
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^
{
popContents.view.frame = CGRectMake(160, 70, 350, 350);
[self.view.superview bringSubviewToFront:self.view];
[self.view.superview addSubview:popContents.view];
}
completion: ^(BOOL finished)
{
NSLog(#"DONE");
}];
so what happens here is that the table view rotates while the popContents view zooms to position.. I understand that is what will happen since I had given transitionWithView:self.view
however, how will I be able to add this effect to the popContents view ( the view which zooms to position)... is it possible?
I tried transitionWithView:popContents.view but that does not seem to have any additional effect to the zooming animation.
Could someone tell me what I am doing wrong?

animated popup view similar to one in Ipad music folder

I would like to know what is the name of the functionality that is used in the Ipad's Music folder, where when an album folder is clicked, details regarding that album pops up in an animated view.
I tried using presentModelViewController but its functionality is different.
It would be great if someone could help me out.
I just managed to get sth. like this to work using CoreAnimation / QuartzCore Framework...
be sure to
#import <QuartzCore/QuartzCore.h>
when you want to animate, use CATransform3Dand the poorly documented CATransform3D.m34 property. this will do the first half of the animation (assuming 200x200<->450x450 with 180° rotation):
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -1000; // this turns on perspective!
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 90.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
someView.layer.transform = rotationAndPerspectiveTransform;
someView.bounds = CGRectMake(0, 0, 325, 325);
[UIView commitAnimations];
for the second half of the animation, you have to add/remove your view to the hierarchy. this example shows hiding/showing of a view that already exists as a subview of someView, it also makes use of a BOOL isUp instance variable (the first half of the aniation is independent of the isUp-flag!)
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if (flag) {
if (isUp) {
someSubView.hidden = YES; // hide subview
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
CATransform3D rotationAndPerspectiveTransform = CATransform3DRotate(someView.layer.transform, -90.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
someView.layer.transform = rotationAndPerspectiveTransform;
someView.bounds = CGRectMake(0, 0, 200, 200);
[UIView commitAnimations];
isUp = NO;
} else {
someSubView.hidden = NO; // Show subview
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
CATransform3D rotationAndPerspectiveTransform = CATransform3DRotate(someView.layer.transform, 90.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
someView.layer.transform = rotationAndPerspectiveTransform;
someView.bounds = CGRectMake(0, 0, 450, 450);
[UIView commitAnimations];
isUp = YES;
}
}
}
one last thing: everything in your view will appear mirrored, it might not be the ideal solution, but mirroring back by applying a CGAffineTransform to the subview does the trick:
- (void)viewDidLoad
{
[super viewDidLoad];
someSubView.transform = CGAffineTransformMakeScale(-1, 1);
isUp = NO;
}
i'm alredy a month late with this solution but i hope it helped someone :)
i first tried using the animateWithDuration:animations:completion: block-based API but that turned out to lag heavily (no smooth first/second-half animaiton even without touching subviews).
On the iPad you have several different options with regards to animating a modal view controller, you can find them here: UIModalTransitionStyle.
However, if you are referring to the "zoom and flip" sort of effect on the album I'm pretty sure this is private behaviour so you would need to develop this yourself.... you might be able to accomplish this with Core Graphics/Quartz.

Resources