Lucas Huang
Lucas Huang

Reputation: 4016

How to draw on the entire screen with all UI elements on top in iOS?

I am working on a side project that it needs to draw on whatever it's displaying on the current screen. However, UIGraphicsBeginImageContextWithOptions only gets me the content of that view only but the entire screen. The drawing view contains many more UI elements and those are not getting drawn. I am just wondering how I should handle it.

Here is how I used to get the current context(self is an instance of UIView):

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);

Upvotes: 1

Views: 217

Answers (1)

dirkgroten
dirkgroten

Reputation: 20702

You first need to have a UIView that covers the entire screen. Then you can draw in the entire UIView. Which UIView are you using now?

To create a UIView that covers the entire screen, you should either add a subview to the main window ([UIApplication sharedApplication].keyWindow) or if you're in a navigationController add a view as overlay to the view hierarchy ([self.navigationController.view addSubview:overlayView]). See this post

Upvotes: 2

Related Questions