2014-07-02 213 views
0

我有一個可容納20個太陽鏡的滾動視圖,當調用該功能時,它帶來了一個新的視圖,太陽鏡2×2共20個(19和20在底部的scrollview)。 它可以很好地適用於iPhone5,但在iPad上,它只能達到16,如果我嘗試拖動,可以看到其餘4個太陽鏡,但我無法選擇它們,因爲滾動視圖會彈回到底部'它認爲是16.UIScrollView不滾動到底部

這是在一個iPad空氣,所以我不知道它是否會有這個問題與不同的分辨率。

這就是我所說的視圖;

- (IBAction)glassesClick:(id)sender 
{ 
    [(AppDelegate*)[[UIApplication sharedApplication] delegate] playSoundEffect:1]; 
    [scroll scrollRectToVisible:CGRectMake(0, 0, 5, 5) animated:NO]; 

    glassesView.frame = CGRectMake(0, -[[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height); 
    [self.view addSubview:glassesView]; 

    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^ 
    { 
     glassesView.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height); 
    } completion:nil]; 
} 

滾動容器視圖設置;

{ 
    for(UIView *view in [scroll subviews]) 
     [view removeFromSuperview]; 

    scroll.contentSize = CGSizeMake(scroll.frame.size.width, 1760); 

    for(int i = 0; i < 20; i++) 
    { 
     int xCoord = 0; 
     if(i % 2 == 0) 
      xCoord = 57; 
     else 
      xCoord = 188; 


     UIButton *glasss = [[UIButton alloc] initWithFrame:CGRectMake(xCoord, 20 + i/2 * 150 + i/2 * 20, 75, 150)]; 

     if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
     { 
      int xCoord = 0; 
      if(i % 2 == 0) 
       xCoord = 156; 
      else 
       xCoord = 462; 

      glasss.frame = CGRectMake(xCoord, 20 + i/2 * 300 + i/2 * 20, 150, 300); 
      scroll.contentSize = CGSizeMake(scroll.frame.size.width, 2580); 
     } 

     glasss.tag = i + 1; 
     [glasss addTarget:self action:@selector(glassChosen:) forControlEvents:UIControlEventTouchUpInside]; 
     [glasss setImage:[UIImage imageNamed:[NSString stringWithFormat:@"glass%d.png", i + 1]] forState:UIControlStateNormal]; 
     [[glasss imageView] setContentMode:UIViewContentModeScaleAspectFit]; 

     if(i >= 10) 
     { 
      if([[[NSUserDefaults standardUserDefaults] objectForKey:@"purchased_glasses"] isEqualToString:@"NO"]) 
      { 
       UIImageView *locked = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20, 25)]; 
       locked.image = [UIImage imageNamed:@"lock_button.png"]; 
       [glasss addSubview:locked]; 
       [locked release]; 

       [glasss removeTarget:self action:@selector(glassChosen:) forControlEvents:UIControlEventTouchUpInside]; 
       [glasss addTarget:self action:@selector(chooseLockedFlavor) forControlEvents:UIControlEventTouchUpInside]; 
      } 
     } 

     UIImageView *backGlass = [[UIImageView alloc] initWithFrame:glasss.frame]; 
     backGlass.image = [UIImage imageNamed:@"back_glass.png"]; 
     [backGlass setContentMode:UIViewContentModeScaleAspectFit]; 
     [scroll addSubview:backGlass]; 
     [backGlass release]; 

     [scroll addSubview:glasss]; 
     [glasss release]; 
    } 
} 
+0

您是否打開了autolayout?您可能需要設置滾動視圖的contentSize。 – brandonscript

+0

嗨,我已經添加了其餘的代碼來顯示scrollview容器 – user3355723

+1

'scroll.contentSize = CGSizeMake(scroll.frame.size.width,1760);'你明確地設置contentSize的高度。因此,您可能會阻止您的iPad視圖。嘗試動態設置它(或者根本不設置它) – brandonscript

回答

0

在這一細分市場:

scroll.contentSize = CGSizeMake(scroll.frame.size.width, 1760); 

我們發現你明確地設置contentSize的高度。因此,您可能會阻止您的iPad視圖。嘗試動態設置它(或者根本不設置它!)。

0

Set scrollViewcontentSize in viewDidLayoutSubviews而不是viewDidLoad

override func viewDidLayoutSubviews() { 
     super.viewDidLayoutSubviews() 
     scroll.contentSize = CGSize(scroll.frame.size.width, 1760) 
    }