【发布时间】:2013-07-10 00:11:06
【问题描述】:
正在寻找一种方法来实现双击可逆的“全屏”动作,但我没有成功!
更详细地说,有 2 个 UIView : - 顶视图容器 - 底部视图容器
当我双击超级视图时,视图“bottomViewContainer”扩展到全屏,我再次双击,视图恢复到原来的大小。
它应该在纵向模式和横向模式下工作!
这是我到目前为止所做的:
-(void)handleDoubleTap:(UITapGestureRecognizer *)sender {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
if (sender.numberOfTapsRequired == 2){
NSLog(@"if gesture up - LS");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 0.0, 480.0, 300.0);}
completion:^(BOOL finished){
NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
} else if (sender.numberOfTapsRequired == 2) {
NSLog(@"else if gesture down - LS");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 84.0, 480.0, 216.0);}
completion:^(BOOL finished){
NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
}
else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
if (sender.numberOfTapsRequired == 2) {
NSLog(@"if gesture down - PT");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 640.0);
}
completion:^(BOOL finished){
NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
else if (sender.numberOfTapsRequired == 2) {
NSLog(@"else if gesture up - PT");
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
bottomContainerView.frame = CGRectMake(0.0, 244.0, self.view.frame.size.width, 216.0);
}
completion:^(BOOL finished){
NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
}];
}
}
}
【问题讨论】:
-
不完全确定您的意思。我的理解是,您希望能够双击并使全屏图像“返回”到其原始位置。要包括的其他一些细节是这个视图是否弹出,它正在显示什么,如果它是动态的,等等。
-
还有一点需要注意的是,你的第一个
elseif statement有condition || NO,所以它永远不会被调用,特别是因为你的 if 条件匹配 elseif 条件 -
你想要 topContainerView 还是只有 bottomContainerView 的效果?
-
没错,是的,这是我的代码中的一个小错误(否)。这里的原理是一样的 --> stackoverflow.com/questions/17506027/… 除了这不是“滑动手势”而是双击!!!
-
是的,当然,同样的效果!
标签: ios uiview toggle fullscreen