2012-12-11 49 views
0

我試圖做一個動畫,當一個人從屏幕上的A點到B點點擊時,對象應該緩慢地從A點滑到B點(水平方向)。 I'順便說一下動畫中的新動畫。CGPoint for for loop的動畫

 [UIView animateWithDuration:10 
           delay:0 
          options:nil 
         animations:^ { 

          if(magnifier != nil){ 
           [magnifier removeFromSuperview]; 

          } 

          magnifier = [[MagnifierView alloc] init]; 

          magnifier.viewToMagnify = imageView; 
          magnifier.touchPoint = newPoint; 
          [imageView addSubview:magnifier]; 
          [magnifier setNeedsDisplay];        
         } 
         completion:nil]; 

,但由於某種原因,它是移動它一路上揚並最終以一種不可思議的曲線選點的B.。

我該如何正確地做到這一點?

回答

1

請勿使用循環。只需使用您擁有的動畫塊即可。

  • 塊之前,將對象點A
  • 在塊中,將其設置爲點B的嵌段將導致其動畫。
  • 另外,初始化動畫塊外的對象。

例子:

// initialize your object outside the block 
magnifier = [[MagnifierView alloc] init]; 
[magnifier setFrame:CGRectMake(0, 0, 100, 100)]; // for example, start at 0, 0 (width and height set to 100 for demo purposes) 
[imageView addSubview:magnifier]; 

[UIView animateWithDuration:10 
delay:0 
options:nil 
animations:^ { 

    // inside the animation block, put the location you want the magnifier to move to 
    [magnifier setFrame:CGRectMake(500, 0, 100, 100)]; // for example, move to 500, 0 

} 
completion:^(BOOL finished) { 

    // do anything you need after here 

}]; 

而且因爲如果你想在動畫或UIViewAnimationOptionCurveLinear的開始和結束的寬鬆政策的效果,如果你想,沒有寬鬆的同樣定時動畫,你可以設置UIViewAnimationOptionCurveEaseInOut選項(有是其他人可用,查找UIViewAnimationOptions)。

+0

這仍然會緩慢地移動它直穿過? – user1066524

+0

是的,這段代碼會將它從左上角(0,0)對角線移動到右下角(500,500),直線 – Anton

+0

我的意思是直接從點A到點B,而不是對角線。 – user1066524