ScrollView中添加一个视图,实现让其始终固定在某个位置,如最底部的位置。方法是自定义一个继承UIScrollView,重写它的layoutSubviews方法。代码如下:
#import "MyScrollView.h" @implementation MyScrollView{ CGFloat _preOffsetY; } -(void) layoutSubviews { if(_isScrolled){ [super layoutSubviews]; CGRect rect; for (UIView *view in self.subviews) { if ([view isKindOfClass:[UIScrollView class]] || [view isKindOfClass:[UIImageView class]]) { rect = view.frame; rect.origin.y = rect.origin.y-_preOffsetY + self.contentOffset.y; view.frame = rect; } } } _preOffsetY = self.contentOffset.y; } @end