1

我的问题是我有一个图像,我可以将它自上而下移动。但我想要的是图像应该在整个屏幕上随机移动。这个问题可能会在堆栈上以不同的方式提出,但我无法得到它。此外,图像在移动时应该会褪色,当我触摸/单击图像时,它应该会给我一个不同的视图。

4

1 回答 1

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 .....
        }];
    }
}
于 2013-06-20T13:06:06.020 回答