如何移动UIImageView?

时间:2010-10-15 12:56:42

标签: animation uiimageview ipad nstimer

继承人: 我在viewDidLoad中编写了一个UIImageView,我希望它能够使用我的fonction buttonPressed **向下移动而不像我那样创建其他子视图。

继承代码。

- (void)viewDidLoad {

[super 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 target:self selector:@selector(buttonPressed :) userInfo:nil repeats:NO];

[self.view addSubview:banetteView];

}

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

}

- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)完成上下文:(void *)context {

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

}

1 个答案:

答案 0 :(得分:1)