1

我正在开发一个应用程序。我想使用下面的代码将 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];

}
 } 

但是这个正在将视图从右侧最后一个边缘移动到左侧。但我只需要在框架大小内移动。我不需要从右侧边缘开始。所以请告诉我该怎么做。

4

3 回答 3

2

编辑:

 [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"];
于 2012-09-25T06:59:14.067 回答
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];
于 2013-02-15T10:03:00.680 回答
0

我不认为你需要潜入CA来做这种事情。它可以使用 UIView 动画来完成。这里http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial是一个很好的 UIView 动画教程。

于 2012-09-25T07:01:24.570 回答