|
|
#1 |
|
How to use block for UIView animation?
I have code as below to do UIView animation, but I found that doesn't work in iOS6, I tried to use block but unsuccessful, does anyone help me?
Code:
- (void)animationDidStop:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context {
UIView* backView = (UIView*)context;
[backView removeFromSuperview];
[backView release];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIImage* backImage = [UIImage imageNamed:@"Default.png"];
UIView* backView = [[UIImageView alloc] initWithImage:backImage];
backView.frame = window.bounds;
[window addSubview:backView];
[UIView beginAnimations:@"CWFadeIn" context:(void*)backView];
[UIView setAnimationDuration:1];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context:)];
backView.alpha = 0;
[UIView commitAnimations];
[window makeKeyAndVisible];
return YES;
}
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 Last edited by mikezang; Nov 20, 2012 at 08:20 AM. |
|
|
|
0
|
|
|
#2 | ||
|
Quote:
Quote:
P.S. I'm not sure putting animation code in your didFinishLaunchingWithOptions: is the best place for it. Probably should go in the viewDidAppear: of your first viewController.
__________________
|
|||
|
|
0
|
|
|
#3 | |
|
Quote:
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
||
|
|
0
|
|
|
#4 |
|
You are using iOS 3 Animations, have you tried using UIView animatin block instead?
[UIView animateWithDuration:blah blah]?
__________________
CSS (Counter Strike Source) Tribute - iPad application ![]() iPad Mini, iPad 4, iPad 2, iPhone 3G,4,5, iMac 24", Mac Mini Last gen, Macbook Pro with Dell U2711
|
|
|
|
0
|
|
|
#5 | |
|
Look like he already did:
Quote:
EDIT: Oops, forgot to include the animationDidStop: method. With that added, I get a compile-time error ("Cast of C pointer type 'void *' to Objective-C pointer type 'UIView *' requires a bridged cast") on this line: Code:
UIView* backView = (UIView*)context;
__________________
Last edited by dejo; Nov 20, 2012 at 06:56 PM. Reason: Consecutive posts, added Edit. |
||
|
|
0
|
|
|
#6 |
|
This app was created before ARC, so you need to use no objc compile flag..
|
|
|
|
0
|
|
|
#7 | |
|
Quote:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIImage* backImage = [UIImage imageNamed:@"Default.png"];
UIView* backView = [[UIImageView alloc] initWithImage:backImage];
backView.frame = window.bounds;
[window addSubview:backView];
[UIView animateWithDuration:1 animations:^{
backView.alpha = 0;
} completion:^(BOOL finished){
[backView removeFromSuperview];
}];
[backView release];
}
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
||
|
|
0
|
|
|
#8 | |
|
Quote:
In iOS 5.x I have the next consequence of methods calling: Code:
-[UIViewController initWithCoder:] -[UIApplicationDelegate didFinishLaunchingWithOptions:] -[UIViewController viewDidLoad] -[UIViewController viewWillAppear:] -[UIViewController viewDidAppear:] Code:
-[UIViewController initWithCoder:] -[UIViewController viewDidLoad] -[UIViewController viewWillAppear:] -[UIApplicationDelegate didFinishLaunchingWithOptions:] -[UIViewController viewDidAppear:] Code:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage* backImage = [UIImage imageNamed:@"Default.png"];
UIImageView* backView = [[UIImageView alloc] initWithImage:backImage];
backView.frame = self.view.bounds;
[self.view addSubview:backView];
[UIView animateWithDuration:1.0
animations:^{backView.alpha = 0.0;}
completion:^(BOOL finished) {[backView removeFromSuperview];}
];
[backView release];
}
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
||
|
|
0
|
|
|
#9 | |
|
Quote:
You can use a boolean flag to make sure it only runs once at startup, ie: Code:
if (!animationShown)
{
animationShown = YES;
// ... do animation ...
}
Last edited by dejo; Nov 21, 2012 at 09:09 AM. Reason: Please use [code] tags. |
||
|
|
0
|
|
|
#10 |
|
My bad Dejo, I read it, but I thought he misunderstood what Block meant.
That block looks fine for me, should work to be honest, I use animation blocks in all my apps, with support back to 4.3, so why it's not working in 6 is a mystery for me, sorry. I think it has to do with the applicationDidFinishLaunching, that you should wait with doing that, add a VC in between which does the animation, and not the appdelegate.
__________________
CSS (Counter Strike Source) Tribute - iPad application ![]() iPad Mini, iPad 4, iPad 2, iPhone 3G,4,5, iMac 24", Mac Mini Last gen, Macbook Pro with Dell U2711
|
|
|
|
0
|
|
|
#11 | |
|
Quote:
Are you using Storyboards in iOS 5 and XIBs in iOS 6 or something? Or is your initialization code different on the different OS versions? It seems odd that the order of the setup calls would be different like that, and seems like it would break a lot of programs in the field.
__________________
Regards, Duncan Champney, WareTo. Check out our latest app, Face Dancer, available for free on the App Store. |
||
|
|
0
|
|
|
#12 | |
|
Quote:
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
||
|
|
0
|
|
|
#13 |
|
What do you mean "...it seems like storyboard in iOS 6." If you did not add a storyboard file to your project, and write specific storyboard code in your app, you're not using Storyboards. There's no ambiguity about it. You either are or you aren't.
__________________
Regards, Duncan Champney, WareTo. Check out our latest app, Face Dancer, available for free on the App Store. |
|
|
|
0
|
|
|
#14 |
|
Sorry, it is my misunderstanding, like you said, my app is not use storyboard.
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 07:24 AM.







I support the 

Linear Mode
