Present a translucent Viewcontroller on iOS

Source: Internet
Author: User

Today I tried to call on a viewcontroller:

-(void) Presentmodalviewcontroller: (Uiviewcontroller *) Modalviewcontroller animated: (BOOL) animated

To show a translucent viewcontroller:

    Uiviewcontroller *VC = [[[Uiviewcontroller alloc] init] autorelease];
    Vc.view.backgroundColor = [Uicolor colorwithred:0 green:0 blue:0 alpha:0.5];
    [Self PRESENTMODALVIEWCONTROLLER:VC animated:yes];

This can be found in the animation process is translucent, but after the end of the animation will not see the content of the following Viewcontroller, black.

Why, then? Search for a more reasonable conclusion:

The "problem" is this iOS is very finicky about not wasting memory,

And since the modal view would completely cover the one beneath it,

It doesn ' t make much sense to keep it loaded.

Therefore, IOS unloads the view that presents the modal one.

You could check this behavior by implementing-viewwilldisappear:and-viewdiddisappear:.

Finally find a problem in so, and a workable solution:

ViewController.view.backgroundColor = [Uicolor clearcolor];
Rootviewcontroller.modalpresentationstyle = Uimodalpresentationcurrentcontext;
[Rootviewcontroller Presentmodalviewcontroller:viewcontroller Animated:yes];

Here are two points: one is to set Modalpresentationstyle as Uimodalpresentationcurrentcontext, and the second is to operate on Rootviewcontroller.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.