查看过渡动画

时间:2013-01-18 04:19:03

标签: iphone ios objective-c xcode cocoa-touch

致电时:

[self dismissViewControllerAnimated:Yes.....];

它与用于呈现视图的任何动画相反。

例如:如果你打电话:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
View * myView = (View *) [storyboard instantiateViewControllerWithIdentifier:@"myViewName"];
[self myView animated:YES completion:nil];

它从底部开始查看,dismissViewControllerAnimated:将使用反向动画关闭视图,因此视图将向下滑动。

有没有办法Present使用向下滑动动画的视图?非常感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

CATransaction使用animation

注意dependsUIInterfaceOrientation的代码Presenting a viewsliding down animation all orienation [CATransaction begin]; CATransition *transition; transition = [CATransition animation]; transition.type = kCATransitionPush; if(viewOrientation == UIInterfaceOrientationLandscapeLeft) [transition setSubtype:kCATransitionFromLeft]; else if (viewOrientation == UIInterfaceOrientationLandscapeRight) [transition setSubtype:kCATransitionFromRight]; else if (viewOrientation == UIInterfaceOrientationPortrait) [transition setSubtype:kCATransitionFromLeft]; else [transition setSubtype:kCATransitionFromRight]; transition.duration = 0.0; [self.view.layer addAnimation:transition forKey:nil]; // add animation in layer of UIView. //Present your View here [CATransaction commit];

current

编辑:在这些方法中设置orientation UIInterfaceOrientation viewOrientation;。因此在.h文件中添加iOS version。这些方法可能会根据- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { viewOrientation = interfaceOrientation; return YES; //return according to your requirement } -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { viewOrientation = toInterfaceOrientation; }

进行更改
{{1}}

答案 1 :(得分:0)

当然,您可以像这样进行自己的转换:

 -(IBAction)presentNext:(id)sender {

    UIViewController *next = [self.storyboard instantiateViewControllerWithIdentifier:@"Next"];
    [self.view.window insertSubview:next.view belowSubview:self.view];
    CGAffineTransform t;
    __block NSInteger xOffset, yOffset;
    switch (self.interfaceOrientation) {
        case 1:
            xOffset = 0;
            yOffset = self.view.frame.size.height;
            break;
        case 3:
            t = CGAffineTransformMakeRotation(90 * M_PI / 180);
            next.view.transform = t;
            xOffset = -self.view.frame.size.width;
            yOffset = 0;
            break;
        case 4:
            t = CGAffineTransformMakeRotation(-90 * M_PI / 180);
            next.view.transform = t;
            xOffset = self.view.frame.size.width;
            yOffset = 0;
            break;
        default:
            break;
    }

    next.view.frame = self.view.frame;
    [UIView animateWithDuration:1 animations:^{
        self.view.center = CGPointMake(self.view.center.x + xOffset, self.view.center.y + yOffset);
    } completion:^(BOOL finished) {
        [self presentViewController:next animated:NO completion:^{
            [self.view removeFromSuperview];
        }];
    }];
}