2012-12-04 4 views
1

J'utilise une animation UIView dans laquelle une deuxième vue apparaît du bas et arrive au centre de la vue. Mais il ne fonctionne pas en mode paysage bien que mon application supporte le mode paysage et que j'ai implémenté la méthode "willAnimateRotationToInterfaceOrientation: toInterfaceOrientation". Voici mon code:UIView Animation ne fonctionne pas en mode paysage

-(void) viewWillAppear:(BOOL)animated{ 

    [super viewWillAppear:animated]; 
    self.view.backgroundColor = [UIColor blackColor]; 

    imageView= [[UIImageView alloc] initWithFrame:CGRectMake(0, 499, 320, 0)]; 
    imageView.image = [UIImage imageNamed:@"trans.png"]; 
    [imageView setClipsToBounds:YES]; 
    [imageView setContentMode:UIViewContentModeBottom]; 



    [self.view addSubview:imageView]; 


    [UIView animateWithDuration:1.0f 
          delay:0.5f 
         options:UIViewAnimationOptionCurveEaseOut 
        animations:^(void) { 
         imageView.frame = CGRectMake(0, 92, 320, 320); 

        } 
        completion:NULL]; 


} 


-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
    CGRect screen = [[UIScreen mainScreen] bounds]; 
    float pos_y, pos_x; 
    pos_y = UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]) ? screen.size.width/2 : screen.size.height/2; 
    pos_x = UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]) ? screen.size.height/2 : screen.size.width/2; 

    imageView.center = CGPointMake(pos_x, pos_y); 

} 

Je suppose que je suis mise le cadre de la deuxième vue au mauvais endroit ...

Répondre

0

Vous avez utilisé willAnimateRotationToInterfaceOrientation mais vous devez utiliser didRotateFromInterfaceOrientation.

willAnimateRotationToInterfaceOrientation vous donnera l'orientation avant la rotation.

Il faut donc utiliser ce ..........

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    imageView.center = self.view.center; 
} 

Cela va certainement vous aider ...

une famille heureuse de codage .......... ................. - :)

Questions connexes