【发布时间】:2011-09-24 06:02:41
【问题描述】:
这是我的代码:
- (CGPoint)randomPointSquare {
CGRect frame = [[self view] frame];
//CGFloat rand_x = ((float)arc4random() / (float)UINT_MAX) * (float)_window.frame.size.width;
NSInteger side = arc4random() / (UINT_MAX/4);
CGFloat offset = 0;
switch(side) {
case 0: /* top */
offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.width;
return CGPointMake(offset, -10);
case 1: /* bottom */
offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.width;
return CGPointMake(offset, frame.size.height-150);
case 2: /* left */
offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.height;
return CGPointMake(-10, offset);
default:
case 3: /* right */
offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.height;
return CGPointMake(frame.size.width+170, offset);
}
}
-(void)createNewImageView {
UIImage * image = [UIImage imageNamed:@"abouffer_03.png"];
imageView = [[UIImageView alloc] initWithImage:image];
// Add it at a random point
[imageView setCenter:[self randomPointSquare]];
[[self view] addSubview:imageView];
// Animate it into place
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:8.0f];
[imageView setCenter:CGPointMake(240, 160)];
[UIView commitAnimations];
[imageView release];
}
所以你可以看到有一个 UIView 动画,但现在我想用一个定时器来改变和替换它。但我不知道该怎么做。好吧,如果你知道怎么做,别忘了我希望 imageView 在随机位置创建,然后移动到屏幕中心。谢谢
【问题讨论】:
标签: iphone xcode animation timer uiimageview