2010-12-14 47 views

Répondre

1

Si l'on suppose votre UIImage est dans une UIImageView et la vue de l'image est de 320 x 480 taille ...

Votre bloc d'animation peut appeler une méthode quand il est terminé. Cette méthode réinitialise la position de votre UIImageView et redémarre l'animation.

animation Bloc:

-(void)animate { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:.3]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(myCallback:finished:context:)]; 

    CGRect frame = yourImageView.frame; 
    frame.origin = CGPointMake(0, 480); 
    yourImageView.frame = frame; 

    [UIView commitAnimations]; 

} 

Callback:

(void)myCallback:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 

    CGRect frame = yourImageView.frame; 
    frame.origin = CGPointMake(0, 0) 
    yourImageView.frame = frame; 
    [self animate]; 
} 
0

Voici comment je l'ai écrit mon code moving.h

#import <UIKit/UIKit.h> 
@interface movingViewController : UIViewController{ 
UIImageView *imageView1; 
} 
@property (retain , nonatomic) UIImageView *imageView1; 
@end 

moving.m

#import "movingViewController.h" 
@synthesize imageView1; 
-(void) animate { 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:.3]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(myCallback:finished:context:)]; 

CGRect frame = imageView1.frame; 
frame.origin = CGPointMake(0, 480) 
imageView1.frame = frame; 

[UIView commitAnimations]; 
} 

- (void)viewDidLoad { 

    [super viewDidLoad]; 
} 


-(void)myCallback:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 

CGRect frame = imageView1.frame; 
frame.origin = CGPointMake(0, 0) 
imageView1.frame = frame; 
[self animate]; 
} 

- (void)didReceiveMemoryWarning { 

    [super didReceiveMemoryWarning];} 
- (void)viewDidUnload {} 
- (void)dealloc { 
    [imageView1 dealloc]; 
    [imageView1 release]; 
    [super dealloc]; 
} 
@end 

Im désolé de poser des questions simples mais je suis très nouveau pour Xcode

est que la bonne façon

+0

j'ai fixé les erreurs, mais lorsque je tente de construire et exécuter le code, im obtenir un écran vide .. pourquoi cela se passe-t-il? – sony