开发者

Size of popover in a UIViewController

开发者 https://www.devze.com 2023-03-10 02:52 出处:网络
I had a calculator app that can draw a function. I\'m stuck in an exercise that says: Your 开发者_如何学PythonCalculatorViewController is also going to need to know (and report when asked by the appr

I had a calculator app that can draw a function. I'm stuck in an exercise that says:

Your 开发者_如何学PythonCalculatorViewController is also going to need to know (and report when asked by the appropriate method) what size it should be when displayed in a popover. The best way to do this is to find the bounding box of all the views in your CalculatorViewController’s self.view and then add a little margin around the edges. To calculate the bounding box of the views, you’re going to need to look at the subviews of the CalculatorViewController’s self.view and all of their frames. You might find the function CGRectUnion() convenient for this task.

What cand i do?


Try this

CGRect boundingRect = CGRectZero;
for (UIView *view in self.view.subviews) {
    boundingRect = CGRectUnion(view.frame, boundingRect);
}

self.view.subviews contains all your view's subviews. By iterating over them and adding each subview's frame to a union of the current boundingRect and the subview, you should get a CGRect that is big enough to hold all subviews. You can then add a margin to it.

0

精彩评论

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