2013-06-20 3 views
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 ..... 
     }]; 
    } 
} 
+0

Thats working fine..Thank You –

Смежные вопросы