我在单页应用程序上有一个图像视图,我点击它时它将其设置为全屏大小并且它可以正常工作。但我还希望它在全屏尺寸时点按它时缩小到原来的大小。怎么做?现在,点击它会使它全屏,然后我只能停止运行。这是我的代码:
- (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)];
}
}
非常感谢!
答案 0 :(得分:1)
添加BOOL变量以跟踪它是否为fullScreen。
在.h添加属性
@property (nonatomic, assign) BOOL isFullScreen;
@property (nonatomic, assign) CGRect originalRect;
在viewDidLoad中,添加以下行
self.isFullScreen = NO;
self.originalRect = CGRectMake(0,0,153,230);//replace this by the zoomed out rect size that you want
并在你的放大中:
- (void)Enlarge:(id)sender{
if(!self.isFullScreen){
[ImageView setFrame:CGRectMake(0, 20, (460/1.5), 480-20)]; //enlarge to fullscreen but exclude the status bar.
}else {
[ImageView setFrame:originalFrame];//
}
self.isFullScreen = !self.isFullScreen;
}
关于第二个问题,是的,这应该有用。