2010-12-14 74 views

回答

1

假設你的UIImage是一個UIImageView和圖像的觀點是320×480大小...

你的動畫塊可以調用的方法是完成時。此方法重置您的UIImageView的位置,然後開始播放動畫。

動畫塊:

-(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]; 

} 

回調:

(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

這是我寫我的代碼 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 

對不起問簡單的問題,但即時通訊非常新的Xcode

是正確的做法

+0

我有固定的錯誤,但是當我嘗試建立並運行代碼,即時得到一個空白屏幕..爲什麼會這樣? – sony 2010-12-14 17:44:11