我有一个可以容纳20个太阳镜的滚动视图设置,在调用该功能时,它会带来一个新视图,太阳镜2×2,总共20个(其中19和20位于滚动视图的底部)。 它在iPhone和iPhone上完美运行iPhone5,但在iPad上,它只有16,如果我尝试进一步拖动,我可以看到剩下的4个太阳镜,但我无法选择它们,因为滚动视图刚刚反弹到它认为是16的“底部”。
这是在iPad Air上,所以我不确定iPad 2是否会出现不同分辨率的问题。
这就是我调用视图的方式;
- (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 :(得分:0)
在此细分中:
scroll.contentSize = CGSizeMake(scroll.frame.size.width, 1760);
我们发现您明确设置了contentSize的高度。因此,您可能会阻止您的iPad视图。尝试动态设置(或根本不设置它!)。
答案 1 :(得分:0)
在scrollView
而不是contentSize
设置viewDidLayoutSubviews
viewDidLoad
。
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
scroll.contentSize = CGSize(scroll.frame.size.width, 1760)
}