2010-10-15 84 views
0

繼承人: 我在viewDidLoad中編寫了一個UIImageView,並且我希望它可以隨着我的功能buttonPressed **向下移動,而不需要像我那樣創建其他子視圖。如何移動UIImageView?

繼承人的代碼。

- (無效)viewDidLoad中{

[超級viewDidLoad中];

banetteImage = [UIImage imageNamed:@「myBanette.png」];

UIImageView *banetteView = [[UIImageView alloc] initWithImage:banetteImage]; 
banetteView.frame = CGRectMake(100, -740, 568, 790); 
banetteView.opaque = NO; 

[的NSTimer scheduledTimerWithTimeInterval:2.5目標:自選擇器:@selector(buttonPressed:)USERINFO:無重複:NO];

[self.view addSubview:banetteView]; 

}

- (無效)buttonPressed {

double speed = 1/round(random() % 100) + 1.0; 

[UIView beginAnimations:nil context:banetteView]; 
[UIView setAnimationDuration: 2*speed ]; 

banetteView.frame = CGRectMake(100, -2, 568, 790); 
banetteView.opaque = NO; 

UIImageView *banetteView = [[UIImageView alloc] initWithImage:banetteImage]; 
banetteView2.frame = CGRectMake(100, -740, 568, 790); 
banetteView.opaque = NO; 
banetteView.hidden = YES; 
[self.view addSubview:banetteView]; 

// set a stop callback so we can cleanup the banette when it reaches the 
// end of its animation 
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)]; 
[UIView setAnimationDelegate:self]; 
[UIView commitAnimations]; 

}

- (無效)onAnimationComplete:(的NSString *)animationID完成:(的NSNumber *)完成上下文: (void *)上下文{

UIImageView *banetteView = context; 


double speed = 1/round(random() % 100) + 1.0; 
banetteView.frame = CGRectMake(100, -2, 568, 790); 
banetteView2.opaque = NO; 
[self.view addSubview:banetteView2]; 

[UIView beginAnimations:nil context:banetteView]; 
[UIView setAnimationDuration: 2*speed ]; 


[banetteView release]; 

}

回答