how to make the modal view controller transparent

放肆的年华 提交于 2020-01-05 10:16:15

问题


I am using present view controller for displaying a new view controller from left.. the code i used is..

UIViewController *controller;
UINavigationController *navi;
UIView *popmenu = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 300)];
popmenu.backgroundColor = [UIColor yellowColor];
controller.view = popmenu;
controller.view.superview.backgroundColor = [UIColor clearColor];
navi = [[UINavigationController alloc]initWithRootViewController:controller];
navi.view.superview.backgroundColor = [UIColor clearColor];
CATransition *transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view.window.layer addAnimation:transition forKey:nil];
[self presentViewController:navi animated:NO completion:nil];
navi.view.superview.frame = CGRectMake(0, 0, 200, 540);

the output i got is..

here i can resize the view of the view controller, but how to resize the view controller so that the view present in background i mean the view from which this modal view is called will be visible and i can do operations..like having a button to close this modal view.. thank you..

回答1:


You can make the presented view controller transparent but the presenting view controller will always disappear (i.e. the background becomes black) if you use the presentViewController:animated:completion: method without specifying a UIViewControllerTransitioningDelegate for the presented controller.

Here's a good tutorial that explains how to make custom transitions on iOS 7 http://www.doubleencore.com/2013/09/ios-7-custom-transitions/

And here's my experiment of it: https://github.com/Jafared/CustomTransitionTests

Note that it'll work only on iOS 7




回答2:


I am using this solution.. instead of creating another controller and other stuff..this seem pretty easy.

  [UIView animateWithDuration:1.0 animations:^{
        //Move frame or transform view
        popmenu.frame = CGRectMake(0,0,200,570);
        table.frame = CGRectMake(200, 0, 120, 570);
    }];



回答3:


I used the following approach on iOS7.

It adds the view above the navigation-controller, in the correct orientation, responds to orientation-changes of the new and underlying view-controller and the background is finally transparent.

UIView *rootView = [[[[self view] window] rootViewController] view];
UIView *myView = [[self myViewController] view];
 [myView setFrame:[rootView bounds]];
 [myView setTranslatesAutoresizingMaskIntoConstraints:YES];
 [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
 [rootView addSubview:myView];

This means you have to implement your own animation though.



来源:https://stackoverflow.com/questions/21380735/how-to-make-the-modal-view-controller-transparent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!