美文网首页
iOS 屏幕横屏的实现

iOS 屏幕横屏的实现

作者: 孟小于max | 来源:发表于2019-03-29 10:43 被阅读0次

    在viewDidLoad里写上

    self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
    

    然后要注意的是横屏之后要设置界面的各个控件自动适应约束autoresizingMask

    UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight//这几种如何约束请参照interfacebuilder
    

    下面是布局代码

      _functionView    = [[UIView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height - 50,self.view.frame.size.width,50)];
        _functionView.backgroundColor = [UIColor clearColor];
        _functionView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
        [self.view addSubview:_functionView];
        
        _closeButton = [[UIButton alloc]initWithFrame:CGRectMake(16, 16, 44, 44)];
        [_closeButton addTarget:self action:@selector(doneDidTouch:) forControlEvents:UIControlEventTouchUpInside];
        [_closeButton setImage:[UIImage imageNamed:@"closeVideo@3x.png"] forState:UIControlStateNormal];
        _closeButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
        [self.view addSubview:_closeButton];
    
        _progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(46, 1, 50, topH)];
        _progressLabel.textColor = [UIColor whiteColor];
        _progressLabel.opaque = NO;
        _progressLabel.adjustsFontSizeToFitWidth = NO;
        _progressLabel.textAlignment = NSTextAlignmentRight;
        _progressLabel.text = @"";
        _progressLabel.font = [UIFont systemFontOfSize:12];
        
        _progressSlider = [[UISlider alloc] initWithFrame:CGRectMake(100, 2, width-197, topH)];
        _progressSlider.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        _progressSlider.continuous = NO;
        _progressSlider.value = 0;
    
        _leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(width-92, 1, 60, topH)];
        _leftLabel.textColor = [UIColor whiteColor];
        _leftLabel.opaque = NO;
        _leftLabel.adjustsFontSizeToFitWidth = NO;
        _leftLabel.textAlignment = NSTextAlignmentLeft;
        _leftLabel.text = @"";
        _leftLabel.font = [UIFont systemFontOfSize:12];
        _leftLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
        
        _playButton = [[UIButton alloc]initWithFrame:CGRectMake(16, 0, 44, 44)];
        [_playButton setImage:@"playback_pause.png" forState:UIControlStateNormal];
        [_playButton addTarget:self action:@selector(playDidTouch:) forControlEvents:UIControlEventTouchUpInside];
        
        _bottomShadow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bottom_shadow.png"]];
        _bottomShadow.frame = CGRectMake(0, 0, _functionView.bounds.size.width, _functionView.bounds.size.height);
        _bottomShadow.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        
        [_functionView addSubview:_bottomShadow];
        [_functionView addSubview:_playButton];
        [_functionView addSubview:_progressLabel];
        [_functionView addSubview:_progressSlider];
        [_functionView addSubview:_leftLabel];
    

    相关文章

      网友评论

          本文标题:iOS 屏幕横屏的实现

          本文链接:https://www.haomeiwen.com/subject/fxgkbqtx.html