我的问题是我有一张图片,我可以自上而下。但我想要的是图像应随机移动到整个屏幕上。这个问题可能会在堆栈上以不同的方式提出,但我无法得到它。此外,图像在移动时应该褪色,当我触摸/点击图像时,它应该给我一个不同的视图。
答案 0 :(得分:0)
timer=[NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
UITapGestureRecognizer *recognizer=[[UITapGestureRecognizer alloc] initWithTarget:self action:nil];
[self.view addGestureRecognizer:recognizer];
-(void)fadeMe
{
[UIView animateWithDuration:1.2f animations:^{
[view setAlpha:0.0f];
}
completion:^(BOOL finished){
[view setAlpha:1.0f];
isBackgroundrunning=NO;
}];
}
-(void)onTimer{
if(arc4random() % 10 == 1)
{
if (!isBackgroundrunning) {
[self performSelectorInBackground:@selector(fadeMe) withObject:nil];
isBackgroundrunning=YES;
}
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[touches anyObject];
CGPoint pt=[touch locationInView:self.view];
CGRect applebounds=[view frame];
if (pt.x>applebounds.origin.x && pt.x<applebounds.origin.x+applebounds.size.width && pt.y>applebounds.origin.y && pt.y<applebounds.origin.y+applebounds.size.height) {
[timer invalidate];
applebounds.size.height*=2;
applebounds.size.width*=2;
[UIView animateWithDuration:0.3 animations:^{
[view setFrame:applebounds];
} completion:^(BOOL finished) {
[view removeFromSuperview];
//perform your task here .....
}];
}
}