开发者

Set UIView.frame.size.height to zero to hide content?

开发者 https://www.devze.com 2023-01-07 22:55 出处:网络
UIView *stateView = [getSomeUIView thisOne]; CGRect currentFrame = stateView.frame; if(currentFrame.size.height == 0.0) {
UIView *stateView = [getSomeUIView thisOne];
CGRect currentFrame = stateView.frame;
if(currentFrame.size.height == 0.0) {
    currentFrame.size = CGSizeMake(260, 60);
}
else {
    currentFrame.size = CGSizeMake(260, 0);
}
stateView.frame = currentFrame;

I would expect all the subviews would be hidden when the height of the frame is set to zero however this does not happen (in the iPhone 4.0.1 Simulator). Any suggestions why or alternatives?

I w开发者_如何学JAVAas planing to later animate the frame so it's a sliding effect. I can not use the y position and move it off screen nor can I create a element to hide it behind since I'm working with a background image and everything on top is transparent/alpha layer.


I've got the same problem. Solved it with clipsToBounds property:

stateView.clipsToBounds = YES


Subviews will only change size if you set their springs and struts to do so.

By default, they are set to "stay the SAME width and height, and stay the same distance from top left corner of the parent view".

You can set the springs/struts in Interface Builder, or in code. e.g.:

aSubView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;


Use UIScrollView instead of UIView. UIScrollView is made to hide "overflow" and works perfectly.

0

精彩评论

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

关注公众号