我正在尝试复制 safari 页面滚动视图,它的框架比 iPhone 屏幕略窄。所以根据一些建议,我将滚动视图(450x280 点)放在“clipView”(450x320 点)内。
//viewController methods
-(void)viewDidAppear:(BOOL)animated{
CGRect pagingScrollViewFrame = self.clipview.frame;
pagingScrollViewFrame.size.width = 280;
NSLog(@"clipview h:%f e w:%f",self.clipview.frame.size.height,self.clipview.frame.size.width);
NSLog(@"scrollview h:%f e w:%f",pagingScrollViewFrame.size.height,pagingScrollViewFrame.size.width);
NSLog(@"center clipview :%@",NSStringFromCGPoint(self.clipview.center));
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
NSLog(@"center scrollview:%@",NSStringFromCGPoint(pagingScrollView.center));
pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width *3, pagingScrollViewFrame.size.height);
pagingScrollView.clipsToBounds = NO;
pagingScrollView.center = self.clipview.center;
[clipview addSubview:pagingScrollView];
}
如您所见,我的滚动视图的中心向下移动了 20 点({140, 232})。我的视图 Container 的中心位于{160, 232}。
我哪里错了?我应该玩什么类似内容偏移属性的东西?这个问题与自动布局有关吗?