我正在实现一个 ScrollView 选择器我已经实现了大部分部分,但我仍然坚持在滚动时更改大小。
我正在尝试这样做:
我已经到了这里,我不知道如何使用滚动偏移来更改大小我尝试了很多东西但都失败了我需要帮助
我正在使用 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
最佳答案
这个怎么样:
- 为 slider 中的单元格创建一个特殊的类
- 创建cell时,给view添加宽度和纵横比的
NSLayoutContraints
使用类中的约束创建一个方法来扩展单元格,例如
-(void)expandCell { self.widthConstraint.constant = normalWidth * 1.05f; } -(void)normalizeCell { self.widthConstraint.constant = normalWidth; }
当 View 位于中心时,您调用方法
expandCell
将其扩展 5%,当单元格在外面时,您调用normalizeCell
。为了让事情变得更漂亮,你只需为其设置动画。
关于ios - 如何让 UIView 在滚动时改变它的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38157181/