2013-10-23 57 views
0

我必須位於視圖(故事板)不同的網站幾個按鈕,我想,當我對他們每個人的點擊去到指定的點,秒的動畫

要做到這一點,我把自己的位置和初始大小由:

在viewDidLoad中

originalCenter1 = self.boton1.center; 
originalsize1 = self.boton1.frame; 

originalCenter2 = self.boton2.center; 
originalsize2 = self.boton2.frame; 

和與每個按鈕,動畫相關聯的IBAction爲

CGPoint originalCenter1; 
CGRect originalsize1; 

CGPoint originalCenter2; 
CGRect originalsize2; 

...

-(IBAction)move:(id)sender{ 

UIButton * pressedbutton = (UIButton*)sender; 

[UIView animateWithDuration:3.0 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ 

    CGAffineTransform scale = CGAffineTransformMakeScale(3.0, 3.0); 
    pressedbutton.transform = scale; 
    switch(pressedbutton.tag) 
    { 
     case 0:  
      pressedbutton.center = CGPointMake(784, 340); 

      break; 
     case 1: 
      pressedbutton.center = CGPointMake(784, 340); 

      break; 

當已經都移動了,我有一個按鈕刷新,使我到初始位置。

-(IBAction)refresh:(id)sender{ 

self.boton1.frame = originalsize1; 
self.boton1.center = originalCenter1; 
self.boton1.alpha=1; 

self.boton2.frame = originalsize2; 
self.boton2.center = originalCenter2; 
self.boton2.alpha=1; 

的問題是,在下一次脈衝按鈕,移動到在動畫但「尺度」的效果中所示的位置,不能正常工作!!

任何幫助?

謝謝。

回答

0

我認爲你應該使用塊試試這個...

- (IBAction)tap:(UITapGestureRecognizer *)gesture 
{ 
    CGPoint tapLocation = [gesture locationInView:self.view1]; 
    for (UIView *view in self.view1.subviews) { 
     if (CGRectContainsPoint(view.frame, tapLocation)) { 
      [UIView animateWithDuration:5.0 animations:^{ 
       [self setRandomLocationForView:view]; 
      }]; 
     } 
    } 
} 


- (void)setRandomLocationForView:(UIView *)view 
{ 
    [view sizeToFit]; 
    CGRect sinkBounds = CGRectInset(self.view1.bounds, view.frame.size.width/2, view.frame.size.height/2); 
    CGFloat x = your location.x; 
    CGFloat y = yout location.y; 
    view.center = CGPointMake(x, y); 
} 
+0

非常感謝你! – user1908661

+0

不客氣。 –

相關問題