Relation between UIView and UIImageView regarding animations... iPhone SDK - animation

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.

Related

UiScrollView scrolling UiView

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];
}

Change pushViewController animation direction

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!

UIBUtton title animation for iPhone

I want to put an animation to custom UIButton's title so that the numbers (each title shows a random assigned number) will come rotating. How can i do that?
The problem is i don't want to do this using flipping number images. i am wondering if there is any other way.
Assuming that you have a button called flipLabelButton connected as IBOutlet to your view controller, you can use this code to animate your button to a new label:
- (IBAction)flipLabelText:(id)sender {
NSString *newText = [NSString stringWithFormat:#"%d", rand() % 100];
[UIView beginAnimations:#"flipbutton" context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.flipLabelButton cache:YES];
[self.flipLabelButton setTitle:newText forState:UIControlStateNormal];
[UIView commitAnimations];
}

Removing superview is already done before animation

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).

UIWebView and Animation

I am wondering if there was a way to animate the size and position of a UIWebView.
If I do sth like this:
[UIView animateWithDuration:1.0 animations:^{
self.frame = CGRectMake(20.0, 20.0, 80.0, 80.0);
}];
or
[UIView beginAnimations:#"zoomIn" context:nil];
[UIView setAnimationDuration:2.75];
[UIView setAnimationDelegate: self];
self.frame = CGRectMake(20.0, 20.0, 80.0, 80.0);
[UIView commitAnimations];
while there is a grey box doing the animation,
the content of the WebView instantly switches to the new size without animating.
(the scalesPageToFit property is set to YES)
any suggestions on that?
Haven't cracked the instant changing of the text width yet but you can get rid of the grey box by programmatically changing the background of the UIWebView to clearColor. Doesn't work if you do it through Interface Builder, for some reason.

Resources