如何呈现从底部动画的视图控制器

时间:2015-12-17 06:44:31

标签: ios objective-c ios9

我需要一个透明的视图控制器,它将从底部进入屏幕。我想看到呈现视图控制器透明。我已经写了这段代码。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

RatingPopVC *ratingVc = [storyboard instantiateViewControllerWithIdentifier:@"RatingPopVC1"];


[self.navigationController presentViewController:ratingVc animated:YES completion:nil];

RateView.m文件 -

 (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor clearColor];//[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
}

3 个答案:

答案 0 :(得分:0)

你可以使用CATransition

看看这可能对你有帮助

CATransition *animation = [CATransition animation];
    [animation setDuration:2];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromTop];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    SecondView *sObj=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
    [self.navigationController pushViewController:sObj animated:YES];
    [[sObj.view layer] addAnimation:animation forKey:@"SwitchToView1"];

答案 1 :(得分:0)

只需添加以下代码行

即可
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    RatingPopVC *ratingVc = [storyboard instantiateViewControllerWithIdentifier:@"RatingPopVC1"];
    ratingVc.view.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.5];//you can set alpha value or Clear Color
    ratingVc.modalPresentationStyle = UIModalPresentationCurrentContext;//add this line of code
    [self.navigationController presentViewController:ratingVc animated:YES completion:nil];

希望它可以帮助你......!

答案 2 :(得分:0)

您需要在Navigation上创建一个UIViewController类别。

为透明度制作类别方法。 请按照以下.h file类别

中编写的代码进行操作
@interface UIViewController (navigation)
    - (void)presentTransparentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion;
@end

转到类别<。p>的.M文件

#import "UIViewController+navigation.h"

@implementation UIViewController (navigation)

- (void)presentTransparentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
    /*
    if(SYSTEM_VERSION_LESS_THAN(@"8.0"))
    {
        [self presentIOS7TransparentController:viewControllerToPresent withCompletion:completion];
    } else {
        viewControllerToPresent.modalPresentationStyle =   UIModalPresentationOverCurrentContext;
        [self presentViewController:viewControllerToPresent animated:YES completion:completion];
    }
    */

    // viewControllerToPresent.view.alpha=0.7f;
    viewControllerToPresent.view.backgroundColor = [UIColor clearColor];
    viewControllerToPresent.modalPresentationStyle =  UIModalPresentationOverCurrentContext;
    [self presentViewController:viewControllerToPresent animated:YES completion:completion];
}

-(void)presentIOS7TransparentController:(UIViewController *)viewControllerToPresent withCompletion:(void(^)(void))completion
{
    UIViewController *presentingVC = self;
    UIViewController *root = self;

    while (root.parentViewController) {
        root = root.parentViewController;
    }

    UIModalPresentationStyle originalStyle = root.modalPresentationStyle;
    root.modalPresentationStyle = UIModalPresentationCurrentContext;

    [presentingVC presentViewController:viewControllerToPresent animated:YES completion:^{
        root.modalPresentationStyle = originalStyle;
    }];
}