我發生了這個問題,我向scrollview水平添加了scrollview,而UITextview
添加了滾動視圖,但在模擬器中,視圖無法正常滾動。添加子視圖後,UIScrollView無法滾動
我的問題是:如何設置contentize使其滾動?
下面是代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = scenery.name;
mainScrollView = [[UIScrollView alloc] init];
self.imagePaths = [scenery imagePaths];
imageScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 240)];
imageScrollView.directionalLockEnabled = YES;
imageScrollView.pagingEnabled = YES;
imageScrollView.showsVerticalScrollIndicator = NO;
imageScrollView.showsHorizontalScrollIndicator = NO;
[self AddImgsToScrollView];
self.currentPage = 0;
[NSTimer scheduledTimerWithTimeInterval:1 target: self selector: @selector(handleTimer:) userInfo:nil repeats: YES];
[mainScrollView addSubview:imageScrollView];
//Introduction Text View
introView = [[UITextView alloc] init];
introView.text = scenery.introduction;
introView.editable = NO;
introView.font = [UIFont systemFontOfSize:16.0f];
[introView setScrollEnabled:NO];
CGSize textViewSize = [introView.text sizeWithFont:introView.font constrainedToSize:CGSizeMake(WIDTH-20, FLT_MAX)];
CGRect newFrame = introView.frame;
newFrame.size = textViewSize;
newFrame.origin = CGPointMake(10,245);
introView.frame = newFrame;
[mainScrollView addSubview:introView];
CGFloat scrollViewHeight = 0.0f;
for (UIView *view in mainScrollView.subviews){
if (scrollViewHeight < view.frame.origin.y + view.frame.size.height) scrollViewHeight = view.frame.origin.y + view.frame.size.height;
}
newFrame = mainScrollView.frame;
newFrame.size = CGSizeMake(WIDTH, scrollViewHeight);
mainScrollView.frame = newFrame;
NSLog(@"%f/%f", scrollViewHeight,textViewSize.height);
[mainScrollView setContentSize:CGSizeMake(WIDTH, scrollViewHeight)];
[self.view addSubview:mainScrollView];
}
爲什麼你通過將滾動視圖添加到滾動視圖和另一個滾動視圖來使它變得複雜.....你需要給出明確的規範嗎? 你想如何讓你的視圖看起來像? – alpha
[mainScrollView addSubview:imageScrollView];爲什麼在另一個滾動視圖中添加滾動視圖 – Rushabh
檢查視圖的用戶交互設置爲否。所以這個觸摸事件將被髮送到滾動視圖。 –