我需要一些圖像隨機出現在屏幕上,然後開始移動,並檢測結束移動。我如何得到這個?我的意思是檢測結束移動UIView?檢測越界屏幕
這些我的代碼:
imageNames = @[@"some_array_picture"];
image = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[image addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
leftX = arc4random_uniform(6) + 10;
leftY = arc4random()%500;
rightX = arc4random_uniform(220) + 20;
rightY = arc4random()%500;
tempX = rightX;
tempY = rightY;
animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(rightX, rightY, 75, 57.5)];
animationImageView.animationImages = image;
animationImageView.animationDuration = 1;
[self.view addSubview:animationImageView];
[self.view sendSubviewToBack:animationImageView];
[animationImageView startAnimating];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:10.0f];
animationImageView.frame = CGRectMake(leftY, leftY, animationImageView.frame.size.width, animationImageView.frame.size.height);
[UIView commitAnimations];
,因爲我需要在運動結束水平旋轉,有這樣的代碼:
animationImageView.transform = CGAffineTransformScale(animationImageView.transform, -1.0, 1.0);
沒有流暢的動畫在這裏,在我的例子animationImageView移動平滑(( – monroe
MB應使用在屏幕邊界檢測碰撞? – monroe