在我的 UIView 中,我有一个填充第一个 View 的 UIScrollView,因此当内容大于 iPhone 屏幕大小时,用户可以向下滚动页面。它运行良好,但是当用户完成滚动运动时——即移开他的手指,页面会弹回到原来的位置。显然那不是我想要的,如何避免?
这是声明和使用UIScrollView类的UIView类中的相关代码。
@implementation TestView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
}
CGRect scrollViewFrame = CGRectMake(0, 0, 320, 460);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
scrollView.canCancelContentTouches=NO;
[self addSubview:scrollView];
CGSize scrollViewContentSize = CGSizeMake(320, 500);
[scrollView setContentSize:scrollViewContentSize];
CGRect rectForBigRedSquare = CGRectMake(50, 50, 200, 200);
UILabel *redSquare = [[UILabel alloc] initWithFrame:rectForBigRedSquare];
[redSquare setBackgroundColor:[UIColor redColor]];
[scrollView addSubview:redSquare];
return self;
}
另一个问题是:如何让用户只能向下滚动,即看到底部不在 View 中的内容,但不能向上滚动,以便之前有空间内容的开始。在
最佳答案
基本上你只需要根据内容设置你的scrollview的contentSize。
CGSize scrollViewSize = CGSizeMake(newWidth, newHeight);
[self.myScrollView setContentSize:scrollViewSize];
关于ios - 用户完成滚动后,UIScrollView 不会停留在原地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8180087/