iOS 屏幕橫屏的實(shí)現(xiàn)

在viewDidLoad里寫(xiě)上

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

然后要注意的是橫屏之后要設(shè)置界面的各個(gè)控件自動(dòng)適應(yīng)約束autoresizingMask

UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight//這幾種如何約束請(qǐng)參照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];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容