I'm pretty new to iOS animations, I've been trying to accomplish something that in my head seems very simple but I am not sure what would be the best way to implement such a thing.
Usage
User clicks on a tab located on the right side of the app.
A small window slides from the side (or below doesn't really matter direction right now)
The sliding object is a UIScrollView currently
Here's a small draft so you guys have an idea
http://dl.dropbox.com/u/919254/animations.png
The black is the tab, there are severals below. When clicked, the red one shows up from a particular direction.
My questions are:
How could I accomplish an animation like that?
Any good tutorials out there you guys can refer me to?
Seeing sample code here wouldn't hurt!
In your view did load:
// Hide scrollView off screen (x=320 for iPhone/iPod)
scrollView.frame = CGRectMake(320, 0, scrollView.frame.size.width, scrollView.frame.size.height);
[self.view addSubview: scrollView];
In your method for opening the view:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// Assuming 0 is the x-coordinate of where you want your view to go
scrollView.frame = CGRectMake(0, 0, scrollView.frame.size.width, scrollView.frame.size.height);
[UIView commitAnimations];
This will animate your scrollView from the right to the left
Related
Right, so I have a class called SimpleCalculator, in the interface builder I have a button with an IBAction. When I press the button it adds a subview that contains complex functions and then animates it so it slides up from the bottom.
The issue I am having is when I run it on iPad it will always take up the full screen to show the functions, however I want it to only take up 75% of the screen as it does when I run it on iPhone.
Here is the code I have currently to do this:
- (IBAction)advancedButton:(id)sender {
UIView * advancedView = advancedCalculator.view;
[advancedView setFrame:CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:advancedView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[advancedView setFrame:CGRectMake(0, self.view.bounds.size.height * 0.25, self.view.bounds.size.width, self.view.bounds.size.height)];
[UIView commitAnimations];
}
There is an easy method that I'd suggest you. Disable auto-layout and size class in the storyboard and try using manual method. It is very simple :) :) Let me know, if you're not clear :)
I'm trying to make my first animation. Currently I'm using animateWithDuration:animations and transitionFromView:toView:duration:options:completion:, but I'm not sure if I'm in "correct page".
What I want to do is to create such animation: in the left upper corner user taps on button and UITableView arrives from the left side of the screen.
I never did any animation in iOS SDK so any help will be appreciated: similiar problems in StackOverflow, some tutorials etc. I don't know where should I begin.
Assume you have a UITableView as subview of a UIViewController's view.
First, before the animation, set the UITableView out of the screen, use center or frame property:
CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
self.theTableView.frame = CGRectMake(-screenFrame.size.width, 0.0, screenFrame.size.width, screenFrame.size.height);
Then, complete the animation code:
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.theTableView.frame = CGRectMake(0.0, 0.0, screenFrame.size.width, screenFrame.size.height);
}
completion:nil];
Hope it will help you! :D
I have been trying to build an entry effect for a logo to come from the top of the screen to the bottom and remain there when a new view loads in my application. I have seen all of the tutorials that use NSTimer to bounce an image but once my logo hits the bottom it needs to exit. I'm going to read up on animation block codes to see if my solution resides there.
Apologies I'm a new be and am very grateful for the assistance.
Set logo frame to top and then:
[UIView beginAnimations: #"moveLogo" context: nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
logoToMove.frame = CGRectMake( final frame at the bottom );
[UIView commitAnimations];
logoToMove is your logo, give it an outlet and hook it in xib.
So you will set the initial frame and in the animation - the final frame. The animation will do the rest of the job.
Change UIViewAnimationCurveLinear to a desired one if you don't like that. Also the duration to speed up or slow down the movement.
To remove the view at the end of your animation, the easiest way would be to use blocks :
logoToMove.frame = topRect;
[UIView animateWithDuration:duration
animations:^{
logoToMove.frame = bottomFrame;
}
completion:^(BOOL finished) {
[logoToMove removeFromSuperview];
}
];
Doing it like that gives you control over the animation and on what to do once it's finished in a single method
I have two animations running; show search bar and show banner. Both those animations are resizing the same view and if they are running on the same time (Which they are) the latest animation will cancel the resize. Is there anyway to check if UIView is currently animating and then standby for animation?
I'm pretty sure I'm not using CAAnimations, since Cocoa not is detecting such class.
This one is running when an ad was received. Unfortunately, that is the same time as ShowSearch is running.
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
if (!hasloaded) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 1.0];
[bannerView_ setFrame:CGRectMake(0, self.view.frame.size.height, bannerView_.frame.size.width, bannerView_.frame.size.height)];
// move and grow
[bannerView_ setFrame:CGRectMake(0, self.view.frame.size.height-50, bannerView_.frame.size.width, bannerView_.frame.size.height)];
// set original position
[UIT setFrame:CGRectMake(UIT.frame.origin.x, UIT.frame.origin.y, UIT.frame.size.width, UIT.frame.size.height)];
// move and grow
[UIT setFrame:CGRectMake(UIT.frame.origin.x, UIT.frame.origin.y, UIT.frame.size.width, UIT.frame.size.height-50)];
[UIView commitAnimations];
hasloaded = true;
}
}
You can use the completion block in the UIView method +animateWithDuration:animations:completion: (which is a more modern alternative to beginAnimations/commitAnimations) to chain multiple animations (I'm guessing this is what you want to do?).
If you select your code while entering it and press control + K, you will preserve formatting and make it pretty. Try it. Reading the wall of text made from pasting code into a true-type non-color-formatted environment.
Nick Weaver says:
A UIView has a layer (CALayer). You can send animationKeys to it which will give you an array of keys which identify the animations attached to the layer. I suppose that if there are any entries, the animation(s) are running. If you want to dig even deeper have a look at the CAMediaTiming protocol which CALayer adopts. It does some more information on the current animation.
Hi there I'm having some problems coding an animation for a UIView in my iPhone app. I'm trying to set an animation for the frame of the UIView after i updated the frame property. Here is the code.
//old frame values are: 0, 0, 15, 37
//set the frame for hiding the arrow
[arrow setFrame:CGRectMake(-15, 100, 15, 37)];
//Create an animation to let the arrow slide in the view.
[UIView beginAnimations:#"SlideInArrow" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:true];
[UIView setAnimationDuration:1.0];
[symbolArrow setFrame:CGRectMake(0, 100, 18, 37)];
[UIView commitAnimations];
this code is a part of a method i wrote. It will be fired when the user is pressing a button. i suggest, that the UI won't update the new frame values to the object. Instead the animation uses the old values. Why is it so? Is there a way to get the view or the animation to get the new frame values?
You're setting animationBeginsFromCurrentState:, which explicitly tells the system to animate based on where the view currently is on the screen. At this point in time, the frame is still at {0,0} because the run loop hasn't completed, so none of your previous setFrame: transactions have been applied. First, take this line out, which may fix it by itself. If not, there are other ways to set the fromValue the way you describe.
The basic flow is odd, however. If the code is as you suggest, the arrow is on screen at {0,0}, and you're going to make it vanish and slide back on. Is that really the animation you're going for, or is there more animations that you've left out? What's the full effect you're trying to achieve?
Note that you have arrow in one case and symbolArrow in another, which I assume is a typo, but would definitely be a problem if these were different objects.
replace this line
[symbolArrow setFrame:CGRectMake(0, 100, 18, 37)];
To
[arrow setFrame:CGRectMake(0, 100, 18, 37)];
and also
remove this line
[UIView setAnimationBeginsFromCurrentState:true];