I have an app where a movie view is a kind of loading screen, and it's on top of my root controller, splitViewController. When the movie has finished, i want to remove it from the superview, animated. I'm using this code now, where mpmctr my movie controller is:
[UIView beginAnimations:#"blablablab" context:NULL];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:splitViewController.view.superview cache:NO];
[UIView setAnimationDuration:.5];
[mpMCtr.view removeFromSuperview];
[UIView commitAnimations];
When this code runs, mpmctr removes itself from the superview but not animated. This is happening when the splitviewcontroller is already on the screen.
Im using this code for putting mpmctr on the view in the delegate method didfinishlaunching.
[window addSubview:splitViewController.view];
[splitViewController.view addSubview:mpMCtr.view];
I hope that you guys can help me with this problem,
Thanks in advance.
A UIView animation can't animate removal from superview, but you could for example animate its alpha down to zero, then you could do this to remove the view after your animation has completed.
[UIView setAnimationDidStopSelector:#selector(removeMyView)];
- (void) removeMyView
{
[mpMCtr.view removeFromSuperview];
}
Despite what MDT says, you can actually animate the removal of a view with UIView animation. You just have to use the block-based API that was introduced in iOS 4.
This is the exact sample code from the Apples documentation for transitionWithView:duration:options:animations:completion:
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[fromView removeFromSuperview];
[containerView addSubview:toView]; }
completion:NULL];
It will flip from left, removing fromView and adding toView to containerView (the view that they are added removed from).
Related
in my viewcontroller entered all the objects in a scrollview. One of the buttons inside the scrollView creates an animation.
The scrollView get off the page -80.0 orgine.y
So far so good .. Now I want that when you click on the button the scrollview and then goes back down to -80.0 to +80.0 automatically returning to its original position so ... Can you tell me the best method for you to have this?
This is the action that fulfills my button when pushed ...
- (IBAction)AcceptFriendRequest:(id)sender {
PFObject *SelectedUser = [self.UtentiInAttesa objectAtIndex:[sender tag]];
[SelectedUser setObject:#"Confermato" forKey:#"STATO"];
[SelectedUser saveInBackground];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.2];
[UIView setAnimationBeginsFromCurrentState:YES];
FFScrollView.frame = CGRectMake(FFScrollView.frame.origin.x, (FFScrollView.frame.origin.y - 80.0), FFScrollView.frame.size.width, FFScrollView.frame.size.height);
[UIView setAnimationRepeatAutoreverses:YES];
[UIView commitAnimations];
}
In your button event handler
- (IBAction)myBtnClicked:(id)sender {
// Create new CGRect indicate place where you would scroll to.
// Assume it is called `originalRect`
// Use the following method, it should work
[FFScrollView.scroll scrollRectToVisible:originalRect animated:YES];
}
i read alot about faking the animation of pushViewController, but I'm wondering if there is a way to change the actually animation, because I would like to use the navBar and the BackButton of the navigationController.
Currently I'm using this to animate:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:YES];
[views setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height -40)];
CGRect frame = views.frame;
frame.origin.y = - self.view.bounds.size.height;
[UIView beginAnimations:#"viewSlideUp" context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
views.frame = frame;
[UIView commitAnimations];
}
but I get an overlapping effect, so my view isn't sliding up, the view is sliding away to the top left side.
Has anyone dealed with that problem? Thx for any kinda help!
I'm trying to develop a really simple app in xcode 4. It's a utility app, with one main view and I want to animate a series of photos in the background with a simple alpha fade that loops continuously between 2 or more images.
I found some code in the xcode user documentation, which I've modified (below), but I'm new at this and I'm asking how to set the following code into motion in an existing project, where to put what, what outlets to create, etc.:
// This method begins the first animation.
- (IBAction)showHideView:(id)sender
{
[UIView beginAnimations:#"ShowHideView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(showHideDidStop:finished:context:)];
// Make the animatable changes.
secondImageView.alpha = 0.0;
// Commit the changes and perform the animation.
[UIView commitAnimations];
}
// Called at the end of the preceding animation.
- (void)showHideDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[UIView beginAnimations:#"ShowHideView2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelay:1.0];
secondImageView.alpha = 1.0;
[UIView commitAnimations];
}
There are really two questions I see, first is the animation code on the right track, and second how to integrate it into an application.
The second part is just basic iPhone 101 stuff for which you're better off taking a look at the Big Nerd Ranch books for.
For the first part, the way you're doing animation above is an older style and is more complex than it has to be.
The simplest way is to use animation blocks.
Here is a good introductory post on that, that actually animates alpha of images just as you requested:
http://pragmaticstudio.com/blog/2010/7/28/ios4-blocks-1
I am implementing a very simple flip animation, but the flip isn't there.
I am using an example from the docs as a template, Apple now recommends you use blocks for animations and that this is the approach to take: (from the docs)
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; }
completion:NULL];
Wrapping the two views you want to transition between in a container.
I do it like this.
UIView *container = [[UIView alloc] initWithFrame:target];
[self.view addSubview:container];
[container addSubview:productImage];
UIView *background = [[UIView alloc] initWithFrame:target];
[background setBackgroundColor:[UIColor darkGrayColor]];
[background setAlpha:0.1f];
[UIView transitionWithView:container
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[[[container subviews] objectAtIndex:0] removeFromSuperview];
[container addSubview:background];
}
completion:NULL];
Two strange things happen:
There is no transition, the container displays the productImage (of type UIImageView), then swaps it with the background view. No animation.
The second thing is what led me to believe that this is not the usual typo, was that the
UIViewAnimationOptionTransitionFlipFromRight
is not recognized by Xcode, it will not autocomplete, it is not highlighted. Xcode will only do that if I use the deprecated:
UIViewAnimationTransitionFlipFromRight //i.e. without the Option part
I then started to check my SDK version etc. everything seems to be set to 4.2, XCode is version 3.2.5, both target and project settings has build and deploy target set to 4.2.
What am I missing here?
Hope a set of trained eyes can help me:) thank you in advance.
If you are going with blocks (and everyone should start going with them), please refer to
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion
and/or
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
This code will help you
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
UIViewAnimationTransition transition = UIViewAnimationTransitionFlipFromRight;
[UIView setAnimationTransition:transition forView:[self.navigationController view] cache:NO];
[UIView commitAnimations];
Cheers
I have some animation blocks in my code which are causing my problems when I upgrade to iPhone OS4. I have read that it is now advised to use block-animations so I thought I would see if this solved my problems. Before I was using the following type of code to make an animation...
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:30.0];
[UIImageView setAnimationRepeatCount:1e100f];
[UIImageView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(stop)];
wheel.transform =CGAffineTransformMakeRotation(M_PI*-0.5);
[UIImageView commitAnimations];
I am now planning to change this to use this type of animation (taken from http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW111)
[UIView animateWithDuration:0.2
animations:^{ view.alpha = 0.0; }
completion:^(BOOL finished){ [view
removeFromSuperview]; }]
My question is can I use the above block animation with UIImageView rather than UIView? Basically I guess I want to know what the difference is, if I animate a UIView would I just be animating a UIImage which is inside a UIView? Is this the same as a UIImageView then?!
Sorry I'm confused :-s
UIImageView is a subclass of UIView, so everything that you can do with UIView can be also done with UIImageView.
If you animate UIView, animation would affect all its subviews. So in case you have UIImageView on top of UIView, animation of UIView would affect both - UIView and UIImageView.