2012-09-25 65 views
1

我正在開發一個應用程序。在那裏我想使用下面的代碼從右向左移動uiview。如何使用CATransition將屏幕的uiview部分從右向左移動

-(void)centerAnimation1:(id)sender 
{ 
theview=qstnview; 
CATransition *animation = [CATransition animation]; 
animation.delegate = self; 
[animation setDuration:0.4]; 
[animation setType:kCATransitionMoveIn]; 

if(rhtolft) 
{ 
    [animation setSubtype:kCATransitionFromLeft]; 
} 
else 
{ 
    [animation setSubtype:kCATransitionFromRight]; 
} 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
//[animation setanima] 
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"]; 

[[theview layer] addAnimation:animation forKey:@"SwitchToView1"]; 
[qstnview removeFromSuperview]; 
} 

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ 
    if(animate) 
    { 
    CATransition *animation = [CATransition animation]; 
    animation.delegate = self; 
    [animation setDuration:0.4]; 
    [animation setType:kCATransitionMoveIn]; 
    if(rhtolft) 
    { 
     [animation setSubtype:kCATransitionFromLeft]; 
     rhtolft=NO; 
    } 
    else 
    { 
     [animation setSubtype:kCATransitionFromRight]; 
    } 
    //[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
    //[animation setanima] 

     [[theview layer] addAnimation:animation forKey:@"SwitchToView1"]; 


     [self.view addSubview:qstnview]; 

} 
} 

但是這一個正在從右側最後一條邊的觀點向左side.But我需要的幀大小內移動only.I不需要從右側開始edge.So請告訴我如何做那個。

+0

哎交配剛剛看到這個鏈接演示其顯示您的輸出,只是看到.. http://www.cocoacontrols.com/controls/iiviewdeckcontroller –

回答

1

編輯:

[UIView animateWithDuration:0.33f 
        delay:0.0f 
       options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction 
      animations:^{ 
       [theView setFrame:newFrame]; //set new frame for view where x =200; 
      } 
      completion:^(BOOL finished){ 
       // do whatever post processing you want (such as resetting what is "current" and what is "next") 
      }]; 

從右邊的畫面向左使用CATransition這樣

CATransition *animation = [CATransition animation]; 
[animation setDuration:0.3]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromRight]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

[[theView layer] addAnimation:animation forKey:@"rightToLeftAnimation"]; 
+0

我只需要在屏幕大小範圍內移動視圖。那是我不需要將視圖從右邊緣移動到左邊緣。我需要將視圖從x值200移動到x值100. –

1

使用此代碼與動畫百變形象:

CATransition *transition = [CATransition animation]; 
transition.duration = 1.0f; 
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
transition.type = kCATransitionMoveIn; 
transition.subtype=kCATransitionFromLeft; 
[yourImageViewName.layer addAnimation:transition forKey:nil]; 
+0

這是我正在尋找對於。 –

相關問題