【发布时间】:2011-05-10 17:41:54
【问题描述】:
我对其中的 UIScrollView 和 UIWebView 有一个奇怪的问题。
首先是我的设置:
我将一个 UIView 子类化并添加了以下代码:
.h
@interface MySubclassedView : UIView {
UIScrollView *scrollView;
UIWebView *contentView;
}
@property(nonatomic,retain) UIWebView *contentView;
.m
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self setupContentView];
}
return self;
}
设置内容视图
-(void)setupContentView {
// Content View
self.contentView = [[UIWebView alloc] init];
self.contentView.backgroundColor = [UIColor whiteColor];
// ScrollView
scrollView = [[UIScrollView alloc] init];
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.alwaysBounceVertical = YES;
[scrollView addSubview:self.contentView];
[self addSubview:scrollView];
}
和我的 layoutSubViews
- (void)layoutSubviews {
XLog(""); // something like NSLog
[super layoutSubviews];
scrollView.frame = CGRectMake(0,0, self.width, self.height);
self.contentView.frame = CGRectMake(0,0, self.width, self.height);
}
所有这一切的问题是,当我的滚动视图没有完全滚动到顶部时,它第一次反弹。在滚动视图滚动到顶部或底部后,我无法向下拖动视图,但只要我在拖动,layoutSubviews 方法就会被调用。
为了更好地理解,我制作了一个简短的屏幕视频来演示该行为:http://www.screenr.com/Gy9
感谢所有帮助。如果有不清楚的地方,请在 cmets 中告诉我。
【问题讨论】:
标签: iphone objective-c uiwebview uiscrollview bounce