我在单页应用程序上有一个图像视图,当点击它时我将它设置为全屏大小并且它可以工作。但我也希望它在全屏大小时点击它时缩小到原始大小。怎么做?现在,点击它将使其全屏显示,然后我只能停止运行。这是我的代码:
- (void)Enlarge:(id)sender{
[ImageView setFrame:CGRectMake(0, 20, (460/1.5), 480-20)]; //enlarge to fullscreen but exclude the status bar.
}
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Enlarge:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.cancelsTouchesInView = YES;
[ImageView setUserInteractionEnabled:YES];
[ImageView addGestureRecognizer:tapGesture];
[tapGesture release];
}
我的第二个问题是我有两个由这个视图控制器控制的故事板,一个用于 3.5 英寸屏幕,另一个用于 4 英寸屏幕。我希望我的放大图适合两种屏幕尺寸,以下更改可以解决问题吗?因为我现在没有要测试的 iPhone5。
- (void)Enlarge:(id)sender{
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480){
[ImageView setFrame:CGRectMake(0, 20, (460/1.5), 480-20)];
}
if (iOSDeviceScreenSize.height == 568){
[ImageView setFrame:CGRectMake(0, 20, (548/1.775), 568-20)];
}
}
非常感谢!