【问题标题】:How to make UIView change it size as it scrolls如何让 UIView 在滚动时改变它的大小
【发布时间】:2016-11-04 13:27:11
【问题描述】:

我正在实现一个滚动视图选择器,我已经实现了大部分部分,但我一直在改变它滚动时的大小。

我正在尝试这样做:

我已经到了这里,但我不知道如何使用滚动偏移来更改大小我尝试了很多东西但失败了我需要帮助

我正在使用SwipeView 来获取滚动条

func swipeViewDidScroll(swipeView: SwipeView!) {

    //USE swipeView.currentItemView to access current view
    //USE swipeView.itemViewAtIndex(swipeView.currentItemIndex - 1) to access previous view
    //USE swipeView.itemViewAtIndex(swipeView.currentItemIndex + 1) to access next View


    swipeView.currentItemView.frame = CGRect(x: swipeView.currentItemView.bounds.origin.x, y: swipeView.currentItemView.bounds.origin.y , width: (swipeView.currentItemView.bounds.width + swipeView.scrollOffset) - CGFloat((280 * swipeView.currentItemIndex)), height: swipeView.currentItemView.bounds.height)

}

我已附上该项目,以使您的工作更容易理解我的工作 LINK TO PROJECT

【问题讨论】:

标签: ios objective-c swift uiscrollview


【解决方案1】:

这个呢:

  1. 为滑块中的单元格创建一个特殊的类
  2. 创建单元格后,将宽度和纵横比的NSLayoutContraints添加到视图中
  3. 使用类内的约束创建一个方法来扩展单元格,例如

    -(void)expandCell {
      self.widthConstraint.constant = normalWidth * 1.05f;
    }
    
    -(void)normalizeCell {
      self.widthConstraint.constant = normalWidth;
    }
    
  4. 当视图位于中心时,您调用方法 expandCell 将其扩展 5%,当单元格不在时,您调用 normalizeCell。为了让事情更漂亮,您只需为其设置动画即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多