0

你打电话时:

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

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

例如:如果你打电话:

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

它使视图从底部向上,并dismissViewControllerAnimated:使用反向动画关闭视图,因此视图将向下滑动。

有没有办法通过Present向下滑动动画查看视图?任何帮助是极大的赞赏!

4

2 回答 2

1

用于. CATransaction_animation

注意:下面的代码depends使用in 。UIInterfaceOrientationPresenting a viewsliding down animationall 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.So 添加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;
}
于 2013-01-18T04:39:07.357 回答
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];
        }];
    }];
}
于 2013-01-18T06:06:01.977 回答