It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How can I set animations in app delegate class?
Yes, you can show an animation just after your application loaded.
If you want to animate your "Default.png" to fade out for example when your application loaded, try this :
In AppNameAppDelegate.h :
#import UIKit/UIKit.h
#interface AppNameAppDelegate : NSObject {
UIImageView *splashView;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
#end
In AppNameAppDelegate.m :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default.png"];
[_window addSubview:splashView];
[_window bringSubviewToFront:splashView];
//Set your animation below
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector (startupAnimationDone:finished:context:)];
splashView.frame = CGRectMake(-60, -60, 440, 600);
splashView.alpha = 0.0;
[UIView commitAnimations];
return YES;
}
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[splashView removeFromSuperview];
[splashView release];
}
I'm not sure if it's what are you looking for but maybe...
Hmm...
I think you will have to be a bit clearer.
You are not able to set an animation as the absolute first point of you application.
You can add an image named "Default.png" that will be shown when you application is loading.
There should be no major problems with showing an animation in you AppDelegate, but it will only sho AFTER your application is loaded.
Related
This is a screen shot of map application of iPhone:
How we can implement shuch page in our application. I am a new on iphone and monotouch and don't know whether this is a component that give the availability o folding or a feature on the MKMapView? Or maybe it is a custom code!
Can any body help me about this?
Use this code snippet and it will do the job.
[UIView transitionWithView:urImage
duration:1.5
options: UIViewAnimationOptionTransitionCurlUp
animations^{
urImage.frame = requiredFrame;
}
completion:^(BOOL finished){
//[urImage removeFromSuperview];
// do something after animation has completed
}
];
You can play around with it and plug it where want.
And her is the link to apple's doc's for the uiview animation:
http://developer.apple.com/library/ios/ipad/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html
Edit:
here is a set of codes that is going to give you the same effect: just hook up the inactions properly. it only uses couple of buttons to curl up and curl down so you should be able to do it. just create a single view app and place two buttons in the view and hook up the actions to the right button and there you go.:)
code for .h file:
#interface FirstViewController : UIViewController {
IBOutlet UIView *viewSecond;
IBOutlet UIView *viewFirst;
}
- (IBAction)btnSecondView_Clicked:(id)sender;
- (IBAction)btnFirstView_Clicked:(id)sender;
#end
code for .m file:
#import "FirstViewController.h"
#implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)btnSecondView_Clicked:(id)sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:2.0];
[viewSecond setAlpha:0.0];
[viewFirst setAlpha:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:viewSecond cache:YES];
[UIView commitAnimations];
}
- (IBAction)btnFirstView_Clicked:(id)sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:2.0];
[viewFirst setAlpha:0.0];
[viewSecond setAlpha:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:viewFirst cache:YES];
[UIView commitAnimations];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[super dealloc];
}
#end
hope this will help you take of business.
happy coding.:)
I have an Iphone application in which i want to implement a flipanimation in my splashview,as did in the PATH Application.I am using a seperte viewcontroller to present my splashview.I want to remove it from window with this animation.Can anybody have any idea about how to achieve this.this is what i am doing to add the view.How i can remove this view from the window and add newview with an animation like`
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.startupController = [[StartupViewController alloc] initWithNibName:#"StartupViewController" bundle:nil];
[window addSubview:self.startupController.view];
[self.startupController.activityIndicator setHidden:NO];
[self.startupController.activityIndicator startAnimating];
[window makeKeyAndVisible];
timer = [NSTimer scheduledTimerWithTimeInterval: 2.0
target: self
selector: #selector(handleTimer:)
userInfo: nil
repeats: NO];
// [window addSubview:navigationController.view];
// [window makeKeyAndVisible];
return YES;
}
-(void)handleTimer:(NSTimer*)timer {
[self.startupController.activityIndicator stopAnimating];
[self.startupController.activityIndicator setHidden:YES];
self.startupController.view.layer.anchorPoint=CGPointMake(0, .5);
self.startupController.view.center = CGPointMake(self.startupController.view.center.x - self.startupController.view.bounds.size.width/2.0f, self.startupController.view.center.y);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5];
[UIView setAnimationDelay:1];
self.startupController.view.transform = CGAffineTransformMakeTranslation(0,0);
CATransform3D _3Dt = CATransform3DIdentity;
_3Dt =CATransform3DMakeRotation(3.141f/2.0f,0.0f,-1.0f,0.0f);
_3Dt.m34 = 0.001f;
_3Dt.m14 = -0.0015f;
self.startupController.view.layer.transform =_3Dt;
[UIView commitAnimations];
//[window addSubview:navigationController.view];
//[window makeKeyAndVisible];
}
`when i am doing like this i can have that flip animation.but when the view is flipping i need to have my home view there.But when i am uncomenting the last two lines that functionality is working but there is no animation.Can anybody help me?
Here is one code which i have already used in one of my project.
There i have requirement of opening cover page like a pad.
#pragma mark Open Book Animation
- (void)pageOpenView:(UIView *)viewToOpen duration:(NSTimeInterval)duration {
// first add next view below current view
[self.view.window insertSubview:navigationController.view
belowSubview:self.view];
// set anchor point for the view animation
viewToOpen.layer.anchorPoint = CGPointMake(0.0f, 0.0f);
viewToOpen.center = CGPointMake(0,
(viewToOpen.center.y -
(viewToOpen.bounds.size.height/2.0f)));
// start the Page Open
[UIView beginAnimations:#"Page Open" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(didEndAnimation)];
[viewToOpen.layer setValue:[NSNumber numberWithInt:180]
forKeyPath:#"transform.rotation.x"];
[splashImageView setHidden:YES];
[UIView commitAnimations];
}
Here viewToOpen is the UIView for which animation is required, and duration is the time line for animation.
Hope this is what you required.
Enjoy Coding :)
I like the approach used in this post. Although the animation used there is fading, it's a good container for the animation.
If you also set the animationTransition, you should be able to get the animation you want. Something like this..
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:splashView cache:YES];
This should at least get you started. :-)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to animate a image up and down smoothly. Any one has idea how to do it..
take a look at a easy UIView (UIImageView) animation tutorial
One of the coolest things about iPhone apps is how animated many of them are. You can have views fly across the screen, fade in or fade, out, rotate around, and much more!
Not only does this look cool, but animations are good indicators that something is going on that a user should pay attention to, such as more info becoming available.
Make sure you import following frameworks:
#import <QuartzCore/QuartzCore.h>
#import <CoreGraphics/CoreGraphics.h>
UIImageView *someImage = .....
CALayer *b = someImage.layer;
// Create a keyframe animation to follow a path to the projected point
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:#"scale"];
animation.removedOnCompletion = NO;
// Create the path for the bounces
CGMutablePathRef thePath = CGPathCreateMutable();
// Start the path at my current location
CGPathMoveToPoint(thePath, NULL, someImage.center.x, someImage.center.y);
CGPathAddLineToPoint(thePath, NULL,20, 500.0);
animation.path = thePath;
animation.speed = 0.011;
animation.repeatCount = 1000000;
// Add the animation to the layer
[someImage addAnimation:animation forKey:#"move"];
You can play around with the values until you get your desired results. Accept this as the answer, if it's your solution.
- (void) showProgressView
{
if (progressViewBack.frame.origin.y == 460.0)
{
[self.view bringSubviewToFront:progressViewBack];
[progressViewBack setFrame:CGRectMake(6.0, 460, 308.0, 126.0)];
[progressViewBack setBounds:CGRectMake(0, 0, 308, 126.0)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[progressViewBack setFrame:CGRectMake(6.0, 334.0, 308.0, 126.0)];
[UIView commitAnimations];
}
else if (progressViewBack.frame.origin.y == 334.0)
{
[progressViewBack setFrame:CGRectMake(6.0, 334.0, 308.0, 126.0)];
[progressViewBack setBounds:CGRectMake(0, 0, 308.0, 126.0)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[progressViewBack setFrame:CGRectMake(6.0, 460.0, 308.0, 126.0)];
[UIView commitAnimations];
}
}
I want to use custom splash screen so I am doing this in my app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
homeNavigationController = [[UINavigationController alloc] init];
homeNavigationController.navigationBarHidden = NO;
[homeNavigationController pushViewController:viewController animated:NO];
// Add the view controller's view to the window and display.
[window addSubview:homeNavigationController.view];
[window makeKeyAndVisible];
[self animateSplash];
return YES;
}
- (void)animateSplash {
CGRect cgRect = [[UIScreen mainScreen] bounds];
CGSize cgSize = cgRect.size;
// set default portrait for now, will be updated if necessary
NSString *imageName = #"splash_screen.png";
CGRect imageFrame = CGRectMake( 0, 0, cgSize.width, cgSize.height );
imageStage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
imageStage.frame = imageFrame;
[window addSubview:imageStage];
[window bringSubviewToFront:imageStage];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelay:2];
[UIView setAnimationDuration:3.0f];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(startupAnimationDone:finished:context:)];
imageStage.alpha = 0.0f;
[UIView commitAnimations];
}
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
// remove and clean up splash image view
[imageStage removeFromSuperview];
[imageStage release];
imageStage = nil;
}
This work ok but as my app is Launches in Landscape (Home button right) mode my splash image orientation is not setting correctly.
Just use an image that is rotated to look correct in your orientation.
If you really want to do it in code for some reason, check out How to Rotate a UIImage 90 degrees? for different ways to rotate a UIImage.
You need to tell iOS that you want to launch your app in Landscape mode. You can follow the directions from Apple here to achieve this.
What's the easiest/fastest/most efficient way to perform a gradual (0.5 sec) fade from Default.png to the initial app view?
My initial try, which doesn't work so well .. it's Saturday night, let's see if we can do better :)
UIImageView* whiteoutView = [[UIImageView alloc] initWithFrame:self.view.frame]; // dealloc this later ??
whiteoutView.image = [UIImage imageNamed:#"Default.png"];
whiteoutView.alpha = 1.0;
[self.view.frame addSubview:whiteoutView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelay:0.5];
whiteoutView.alpha = 0;
[UIView commitAnimations];
What about:
UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.view.frame] autorelease];
if (whiteoutView != nil)
{
whiteoutView.image = [UIImage imageNamed:#"Default.png"];
[self.view addSubview:whiteoutView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 0.5];
whiteoutView.alpha = 0.0;
[UIView commitAnimations];
}
(The things you had wrong were setAnimationDelay vs setAnimationDuration, not properly releasing the view and trying to add the view to self.view.frame instead of self.view. The compiler should have caught that last one. Did it?)
Here's a simple view controller that fades out the default image and removes itself from the view hierarchy. The advantage to this approach is that you can use this without modifying your existing view controllers...
#interface LaunchImageTransitionController : UIViewController {}
#end
#implementation LaunchImageTransitionController
- (void)viewDidLoad {
[super viewDidLoad];
self.view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default.png"]] autorelease];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(imageDidFadeOut:finished:context:)];
self.view.alpha = 0.0;
[UIView commitAnimations];
}
- (void)imageDidFadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[self.view removeFromSuperview];
//NOTE: This controller will automatically be released sometime after its view is removed from it' superview...
}
#end
Here is how you might use it in your app delegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//create your root view controller, etc...
UIViewController *rootController = ....
LaunchImageTransitionController *launchImgController = [[[LaunchImageTransitionController alloc] init] autorelease];
[window addSubview:rootController.view];
[window addSubview:launchImgController.view];
[window makeKeyAndVisible];
}
Other than using setAnimationDelay: instead of setAnimationDuration:, it looks pretty good. What don't you like about the results?
Edit: Wow beaten hard.