Ios 通过双击切换全屏操作

Ios 通过双击切换全屏操作,ios,uiview,toggle,fullscreen,Ios,Uiview,Toggle,Fullscreen,寻找一种方法来实现一个“全屏”行动可逆双击,但我没有成功 更详细地说,有两个UIView: -topViewContainer -底部视图容器 当我双击superview时,视图“bottomViewContainer”将扩展到全屏,然后我再次双击,视图将恢复到其原始大小 它应该在纵向模式和横向模式下工作 这就是我到目前为止所做的: -(void)handleDoubleTap:(UITapGestureRecognizer *)sender { if ([[UIApplication shar

寻找一种方法来实现一个“全屏”行动可逆双击,但我没有成功

更详细地说,有两个UIView: -topViewContainer -底部视图容器

当我双击superview时,视图“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); 
                         }];

    }
}        
}请尝试以下代码:

#import "ViewController.h"

@interface ViewController (){
    UIView *topContainerView;
    UIView *bottomContainerView;

    CGRect initialTopContainerView;
    CGRect initialBottomContainerView;

    BOOL isFullScreen;
}

@end

@implementation ViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

        CGSize result = [[UIScreen mainScreen] bounds].size;

        topContainerView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, result.width, result.height/2)];
        topContainerView.backgroundColor = [UIColor redColor];
        topContainerView.tag = 1;
        [self.view addSubview:topContainerView];

        bottomContainerView = [[UIView alloc]initWithFrame:CGRectMake(0.0, result.height/2, result.width, result.height/2)];
        bottomContainerView.backgroundColor = [UIColor blueColor];
        bottomContainerView.tag = 2;
        [self.view addSubview:bottomContainerView];

        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTap:)];
        tap.numberOfTapsRequired = 2;
        [bottomContainerView addGestureRecognizer:tap];

        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTap:)];
        tap2.numberOfTapsRequired = 2;
        [topContainerView addGestureRecognizer:tap2];

        initialTopContainerView = bottomContainerView.frame;
        initialBottomContainerView = topContainerView.frame;

        isFullScreen = false;

    }
    return self;
}

-(void)handleDoubleTap:(UITapGestureRecognizer *)sender {

    CGSize result = [[UIScreen mainScreen] bounds].size;

    int heightSreen = result.height;
    int widthSreen = result.width;

    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
        heightSreen = result.width;
        widthSreen = result.height;
    }

    if (sender.numberOfTapsRequired == 2) {

        CGRect newFrameTop;
        CGRect newFrameBottom;

        isFullScreen = !isFullScreen;

        if (isFullScreen) {

            if (sender.view.tag == 1) {
                newFrameTop = CGRectMake(0, 0, widthSreen, heightSreen);
                newFrameBottom = CGRectMake(0, heightSreen, widthSreen, 0);
            }else{
                newFrameTop = CGRectMake(0, 0, widthSreen, 0);
                newFrameBottom = CGRectMake(0, 0, widthSreen, heightSreen);
            }

            [UIView animateWithDuration:0.5
                                  delay:0.1
                                options:UIViewAnimationOptionBeginFromCurrentState
                             animations:^{
                                 topContainerView.frame = newFrameTop;
                                 bottomContainerView.frame = newFrameBottom;
                             }completion:nil];

        }else{

            [UIView animateWithDuration:0.5
                                  delay:0.1
                                options:UIViewAnimationOptionBeginFromCurrentState
                             animations:^{
                                 topContainerView.frame = CGRectMake(0.0, 0.0, widthSreen, heightSreen/2);
                                 bottomContainerView.frame = CGRectMake(0.0, heightSreen/2, widthSreen, heightSreen/2);
                             }completion:nil];

        }

    }

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

我不完全明白你的意思。我的理解是,您希望能够双击并将全屏图像“返回”到其原始位置。其他一些细节包括是否弹出此视图、显示的内容、是否为动态等。还有一点需要注意的是,您的第一个
elseif语句
具有
条件| |否
,因此,这将永远不会被调用,特别是因为您的if条件与elseif条件匹配。您希望topContainerView具有相同的效果还是只希望bottomContainerView具有相同的效果?确切地说,是的,这是我的代码中的一个小错误(否)。这里的原理相同-->不同的是,这不是“滑动手势”,而是双击!!!是的,当然,同样的效果!太神了祝贺你,它工作得很好!只是横向模式的一个错误修复(它需要重置视图大小),但我认为我可以做到这一点!谢谢