Ios 如何让这些图像以set.y和random.x从屏幕上落下
如何让这些图像以set.y和random.x从屏幕上掉落,并在smallapple1点击屏幕中间时重新生成这些图像 (我希望苹果有一个小间隙,这就是为什么.y需要是一个特定的数字)Ios 如何让这些图像以set.y和random.x从屏幕上落下,ios,objective-c,uiimageview,Ios,Objective C,Uiimageview,如何让这些图像以set.y和random.x从屏幕上掉落,并在smallapple1点击屏幕中间时重新生成这些图像 (我希望苹果有一个小间隙,这就是为什么.y需要是一个特定的数字) ibuiimageview*smallapple1 ibuiimageview*smallapple2 ibuiimageview*smallapple3 ibuiimageview*smallapple4 我见过一些类似的问题,但答案并不符合我现在的问题;) 我已经尝试过这段代码,但是对于生成的许多苹果来说,我的角
ibuiimageview*smallapple1代码>
ibuiimageview*smallapple2代码>
ibuiimageview*smallapple3代码>
ibuiimageview*smallapple4代码>
我见过一些类似的问题,但答案并不符合我现在的问题;)
我已经尝试过这段代码,但是对于生成的许多苹果来说,我的角色是laggy,并且这些苹果相互生成。谁能修复这个代码
-(void)dispatchSomeRaindrops
{
for (int i = 0; i < 5; i++) {
UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"smallapple.jpg"]];
CGFloat halfHeight = view.frame.size.height / 2;
CGFloat x = arc4random() % (int)self.view.frame.size.width;
view.center = CGPointMake(x, -halfHeight);
[self.view addSubview:view];
NSTimeInterval duration = 5 + arc4random() % 10;
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
float endY = self.view.frame.size.height + halfHeight;
view.center = CGPointMake(x, endY);
} completion:^(BOOL finished) {
[view removeFromSuperview];
}];
}
}
-(无效)发送一些雨滴
{
对于(int i=0;i<5;i++){
UIImageView*视图=[[UIImageView alloc]initWithImage:[UIImageName:@“smallapple.jpg”];
CGFloat半高=view.frame.size.height/2;
CGFloat x=arc4random()%(int)self.view.frame.size.width;
view.center=CGPointMake(x,-半高);
[self.view addSubview:view];
NSTimeInterval duration=5+arc4random()%10;
[UIView animateWithDuration:持续时间延迟:0选项:UIViewAnimationOptionCurveEaseIn动画:^{
float endY=self.view.frame.size.height+半高;
view.center=CGPointMake(x,endY);
}完成:^(布尔完成){
[视图从SuperView移除];
}];
}
}
(从Stackoverflow上的一个类似问题中找到此代码)您的问题非常开放,有点像“请告诉我如何解决这个复杂的问题。我不会给您完整的答案,但我会从正确的方向开始:
最简单的方法是使用UIView动画。查看方法animateWithDuration:delay:options:animations:completion:
您可能需要线性动画的选项
将代码传递到完成块中,该块将触发另一个动画
您想让smallApple1停在屏幕中间,还是说当smallApple1停在屏幕中间,但smallApple1继续向下移动时,您想让更多图像显示
我会花一点时间来制定逻辑来做你想做的事情,但这种方法应该会让你开始。谢谢你的回复,邓肯!我希望当smallApple1进入屏幕中央时,会出现更多的图像,但是smallApple1会继续在屏幕下运行。要做到这一点,你必须计算它需要多长时间才能完成r您的apple视图到达屏幕中间,然后使用类似PerformSelect:withObject:afterDelay的方法在适当的延迟后排队等待新对象。