2012-04-20 32 views
0

我有一個包含三個啓用分頁的uiviewcontrollers的uiscrollview。當內容插圖是{0,0,0,0},這是結果:UIScrollView分頁需要手動邊緣插入修改才能正常工作

enter image description here

但是,當我修改滾動視圖的內容插入到具有-7左,這是它的修復: enter image description here

我想弄清楚爲什麼是-7的魔術數字來解決這個問題? 下面是該SliderViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil event:(Event*)event 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     _event = event; 
     conversationVC = [[ConversationViewController alloc] initWithNibName:@"ConversationViewController" bundle:[NSBundle mainBundle] event:_event]; 
     eventVC = [[EventControlViewController alloc] initWithNibName:@"EventControlViewController" bundle:[NSBundle mainBundle]]; 
     suggestionVC = [[SuggestionViewController alloc] initWithNibName:@"SuggestionViewController" bundle:[NSBundle mainBundle]]; 
     [self addChildViewController:conversationVC]; 
     [self addChildViewController:eventVC]; 
     [self addChildViewController:suggestionVC]; 
     // Custom initialization 
    } 
    return self; 
} 
- (void)layoutSubviews 
{ 
    CGFloat curXLoc = 0; 
    CGFloat yMax = 0; 
    for(UIView *view in _scrollView.subviews) 
    { 
     CGRect frame = view.frame; 
     frame.origin.x = curXLoc; 
     view.frame = frame; 
     curXLoc += view.frame.size.width; 
     yMax = MAX(view.frame.size.height, yMax); 
    } 
    [_scrollView setContentSize:CGSizeMake(_scrollView.subviews.count * 320, yMax)]; 
} 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    _scrollView.clipsToBounds = YES; 
    _scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite; 
    [_scrollView addSubview:conversationVC.view]; 
    [_scrollView addSubview:eventVC.view]; 
    [_scrollView addSubview:suggestionVC.view]; 
    [self layoutSubviews]; 
} 

回答

0

代碼如果ü啓動從故事板視圖控制器,只需打開尺寸檢查檢查你的根視圖的框架矩形的x是我沒有使用設置爲0

+0

故事板(支持iOS 4.2)。 – ninjaneer 2012-04-26 04:41:39

+0

您的滾動視圖在哪裏啓動代碼?每個頁面的寬度取決於滾動視圖的框架寬度。所以有兩種可能性。一個是你想在所有頁面之間有一個14像素(在視網膜顯示器上爲28像素)的寬度空間,所以你把滾動視圖的幀寬設置爲「[[UIScreen mainwindow]界限] .frame.with + 7 * 2」,但忘記設置框架的x原點-7居中滾動視圖。要修復它,只需設置滾動視圖的框架的x原點-7。另一個是你想要相同的效果,但你設置contentInset。我不確定這可以做到。但蘋果只是推薦了我之前描述的方式。 – WeZZard 2012-04-27 15:08:10

+0

我的滾動視圖代碼由Interface Builder初始化。我將滾動視圖的框架寬度設置爲320,origin.x爲0.滾動視圖的所有子視圖的寬度爲320,原始位置爲每個子視圖的320 * pagenumber。我不相信我會在頁面之間增加14px的寬度。 – ninjaneer 2012-04-27 19:06:56

相關問題