我正在使用KVO
来观察contentOffset
的{{1}}属性。当用户向下拉UIScrollView
和scrollView
时,我希望滚动视图释放,就像用户将手指从屏幕上移开一样。反正有没有这样做?
答案 0 :(得分:0)
是的,你可以将它的偏移限制在-50.0。
- (void) observeValueForKeyPath:(NSString*)keyPath
ofObject:(id)object
change:(NSDictionary*)change
context:(void*)context
{
//if this is not the only KVO then you should first perform some checks
//if the object and keypath are correct
//otherwise you can omit the check or modify, if your UIScrollView is subclassed
if ([object isKindOfClass:[UIScrollView class]])
{
UIScrollView *scrl = (UIScrollView *)object;
CGPoint offset = scrl.contentOffset;
if (offset.y < -50.0f)
{
offset.y = -50.0f;
scrl.contentOffset = offset;
}
}
}
您可能需要考虑在scrollView
委托方法(didScroll:
和其他方法中移动此代码.KVO是一个很棒的工具,但对于快速更改的值,它可能太昂贵