【问题标题】:UIScrollView height to adjust when width is adjustedUIScrollView 调整宽度时要调整的高度
【发布时间】:2012-01-17 03:51:56
【问题描述】:

我有一个 UIScrollView,我希望在调整宽度时按比例调整框架高度,这可能吗?基本上我说的是当我调整 UIScrollView 的宽度时自动调整 UIScrollView 的框架高度?我尝试将 autoResizingMask 设置为 UIViewAutoresizingFlexibleWidth 和高度,但这不起作用

【问题讨论】:

  • 你如何“调整”滚动视图的宽度?

标签: iphone objective-c ipad uiscrollview


【解决方案1】:

我认为没有一种自动的方法可以做到这一点。但你可以添加一个 UIView+SCaleAddition 来做到这一点:

@interface UIView(RespectScale) - (void)setWidthRespect:(float)w; - (void)setHeightRespect:(float)h; @结尾 @implement UIView(RespectScale) - (void)setWidthRespect:(float)w { 浮动比例 = self.bounds.size.width / self.bounds.size.height; 浮动 h = w/比例; CGRect 边界 = self.bounds bounds.size.width = w; bounds.size.height = h; self.bounds = 界限; } - (void)setHeightRespect:(float)h { // 自己写 } @结尾

【讨论】:

    【解决方案2】:

    你可以这样做:

    //get old proportions
    CGFloat proportion = scrollView.frame.size.width / scrollView.frame.size.height;
    
    CGRect frame = scrollView.frame;
    
    frame.size.width = new_width;
    frame.size.height = new_width * proportion;
    
    scrollView.frame = frame;
    

    【讨论】:

    • 我就是这样做的,但想知道是否有一种无需这样做的自动方法
    • 你可以应用 CGAffineTransformScale,但除此之外,我不这么认为。
    猜你喜欢
    • 2011-09-23
    • 1970-01-01
    • 2011-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多