Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
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;
}
 
Last edited:

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
I have code as below to do UIView animation, but I found that doesn't work in iOS6...
Doesn't work how? You need to be more specific.

...I tried to use block but unsuccessful, does anyone help me?
It might help if you showed us the code of trying to use blocks.

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.
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
Doesn't work how? You need to be more specific.


It might help if you showed us the code of trying to use blocks.

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.
I use this code to make a fade out effect so that should be on startup, in iOS5, you can see that animation, but there is no such effect in iOS6, so I think something is changed in iOS6, you can copy it to your any app for testing both iOS5.1 and iOS6 simulator, you will find the difference.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
...have you tried using UIView animatin block instead?

Look like he already did:

...I tried to use block but unsuccessful...

I use this code to make a fade out effect so that should be on startup, in iOS5, you can see that animation, but there is no such effect in iOS6, so I think something is changed in iOS6, you can copy it to your any app for testing both iOS5.1 and iOS6 simulator, you will find the difference.

I tried that code in both iOS 5.1 and 6.0 Simulator and in both cases I saw no fade-out; there was no difference.

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:

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
You are using iOS 3 Animations, have you tried using UIView animatin block instead?
[UIView animateWithDuration:blah blah]?
I changed it to block as below, but I found this effect is only happened in iOS5 not iOS6, do you know why?
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];
}
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
Look like he already did:
I tried that code in both iOS 5.1 and 6.0 Simulator and in both cases I saw no fade-out; there was no difference.

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;
Hi, I found the reason base on Times of calling application:didFinishLaunchingWithOptions: differs between iOS 5.x and iOS 6, because sequence is different in iOS5 and iOS6.
In iOS 5.x I have the next consequence of methods calling:
Code:
-[UIViewController initWithCoder:]
-[UIApplicationDelegate didFinishLaunchingWithOptions:]
-[UIViewController viewDidLoad]
-[UIViewController viewWillAppear:]
-[UIViewController viewDidAppear:]
But in iOS 6.x it's the next:
Code:
-[UIViewController initWithCoder:]
-[UIViewController viewDidLoad]
-[UIViewController viewWillAppear:]
-[UIApplicationDelegate didFinishLaunchingWithOptions:]
-[UIViewController viewDidAppear:]
so I move my code from didFinishLaunchingWithOptions to viewDidLoad as below, now both fade out in iOS5 and iOS6:
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];
}
 

Reason077

macrumors 68040
Aug 14, 2007
3,605
3,644
so I move my code from didFinishLaunchingWithOptions to viewDidLoad as below, now both fade out in iOS5 and iOS6:

As dejo suggests, you should really put this sort of thing in viewDidAppear. viewDidLoad is not guaranteed to only run when the application starts - views can be loaded and unloaded multiple times depending on memory availability, etc.

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 a moderator:

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
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.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Hi, I found the reason base on Times of calling application:didFinishLaunchingWithOptions: differs between iOS 5.x and iOS 6, because sequence is different in iOS5 and iOS6.
In iOS 5.x I have the next consequence of methods calling:
Code:
-[UIViewController initWithCoder:]
-[UIApplicationDelegate didFinishLaunchingWithOptions:]
-[UIViewController viewDidLoad]
-[UIViewController viewWillAppear:]
-[UIViewController viewDidAppear:]
But in iOS 6.x it's the next:
Code:
-[UIViewController initWithCoder:]
-[UIViewController viewDidLoad]
-[UIViewController viewWillAppear:]
-[UIApplicationDelegate didFinishLaunchingWithOptions:]
-[UIViewController viewDidAppear:]
so I move my code from didFinishLaunchingWithOptions to viewDidLoad as below, now both fade out in iOS5 and iOS6:
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];
}


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.
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
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.
Well, my app used nib file, it seems like storyboard in iOS 6.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Well, my app used nib file, it seems like storyboard in iOS 6.

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.
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
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.
Sorry, it is my misunderstanding, like you said, my app is not use storyboard.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.