我正在努力使我的应用程序兼容iphone 5。在下面的代码中,donebutton适用于iphone 4,但当它涉及到iphone5时,它是不可触摸的!我不知道为什么?
float screenSizeHeight=[UIScreen mainScreen].bounds.size.height;
if(screenSizeHeight==568)
{
UIImageView *my_image_view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Plain_Background2.png"]];
[my_image_view setFrame:CGRectMake(0,20,320,568)];
[self.view addSubview:my_image_view];
[self.view sendSubviewToBack:my_image_view];
imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
[doneButtonOutlet setFrame:CGRectMake(124,470,72,28)];
}
if(screenSizeHeight==480)
{
UIImageView *my_image_view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Plain_Background.png"]];
[my_image_view setFrame:CGRectMake(0,20,320,480)];
[self.view addSubview:my_image_view];
[self.view sendSubviewToBack:my_image_view];
imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 400)];
[doneButtonOutlet setFrame:CGRectMake(124,432,72,28)];
}
这是因为在iPhone 5中scrollView的高度更高,它在你的按钮上方。
那么改变UIButton的原点y
imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
// Here imageScrollView bottom is at 480 pixel and doneButtonOutlet origin is at 470 so either small height of scrollview or change button origin y..
[doneButtonOutlet setFrame:CGRectMake(124,470,72,28)];
希望对你有帮助。