简体   繁体   中英

how to make the modal view controller transparent

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..

You can make the presented view controller transparent but the presenting view controller will always disappear (ie 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

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);
    }];

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM