my goal is to present a transparent uiviewcontroller on top of another uiviewcontroller so that the background will be a viewcontroller..
I'm NOT using storyboard.
For now i just added UIViews instead of UIViewcontrollers and everything works well, buy the problem is that i feel that one viewcontroller that manages all of the views (that could be easly in a seperate view controller) considers as bad practice - it just doesnt feel right.
i was thinking about creating a viewcontroller inside of my base viewcontroller
and then just
[self addSubview:otherVC.view]
so what i get will be a view controller that has a viewcontroller as a property and presents its view as a subview.
does that consider as a bad practice?
what should i do?
self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:modalVC animated:YES];
tnx.
When I needed to make transparent view controller, I made method like this:
- (UIImage *)screenshot:(CGRect)cropRect {
UIGraphicsBeginImageContext(cropRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, -cropRect.origin.x, -cropRect.origin.y - [[UIApplication sharedApplication] statusBarFrame].size.height);
[self.view.window.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Then I passed it to transparent view controller and made it background view
UIImage *bgImage = [self screenshot:self.view.window.frame];
transparentViewController.view.backgroundColor = [UIColor colorWithPatternImage:bgImage];
Something like that. I can use another view for this purpose, it's not necessarily has to be self.view
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.