开发者

How to change the popover background color

My problem is that:

I have a popOver and when it is pop up I want the color of the other views to become gray.

After tapping outside the popover, the popover will dismiss and the color of the other views will change back to normal.

Any开发者_JS百科one can help me? Thanks a lot.


Ok, I find out the solution. I used the UIPopoverControllerDelegate

inside there is a method named:

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController

each time a popover shows up, a UIImageView is added at the top of the background. And by setting its alpha value, the background can be not clear.

each time the popover dismiss by users tapping outside, the method I mentioned above will be called and inside that method just remove the UIImageView we added just now. And it is done!


You need to loop all the subviews, recognize the opaque view and do what you want!

for (UIView *v in [self.view allSubViews])
{
    NSLog(@"%@", [v description] );

    // examples
    if (v.opacity <= 1) { }
    if([v isKindOfClass:[UIView class]]) { }
    // etc
}

hope this helps.


Just as a suggestion, you could ask yourself if it's better for your needs to present a view modally and not a popover. I say that because the behavior you're describing is the classic of a modal view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜