溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

UINavigationController+UIScrollView內(nèi)容視圖全屏顯示的方法

發(fā)布時間:2020-07-22 21:17:45 來源:網(wǎng)絡(luò) 閱讀:1775 作者:NetworkAD 欄目:開發(fā)技術(shù)

我在程序開發(fā)時發(fā)現(xiàn),將UINavigationController+UIScrollView組合起來使用時,我將UIImageView放入UIScrollView時,UIImageView并不是按照我預(yù)想的那樣,以UIScrollView的頂點作為視圖添加的位置,這是由于UINavigationController在添加了導(dǎo)航欄以后,將會以導(dǎo)航欄下方作為UIScrollView的原點位置,有時候我們想完全顯示該視圖的內(nèi)容,解決方法,看下面這個程序


#import "RootViewController.h"
@interface RootViewController ()
@property (retain,nonatomic,readwrite)UIScrollView * scrollView;
@end
@implementation RootViewController
#define HIGHTOFNVBAR    64
#define HIGHTOFTOOLBAR  44
- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    [self.navigationController setToolbarHidden:NO animated:NO];
    
    self.view.backgroundColor = [UIColor blackColor];
    
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    
    
    _scrollView.contentSize = CGSizeMake(960, 0);
    
    _scrollView.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:_scrollView];
    
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    
    [_scrollView addGestureRecognizer:tapGesture];
    
    _scrollView.pagingEnabled = YES;
    _scrollView.userInteractionEnabled = YES;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    
    UIImageView *p_w_picpathView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    UIImageView *p_w_picpathView2 = [[UIImageView alloc]initWithFrame:CGRectMake(320, 0, 320, 480)];
    UIImageView *p_w_picpathView3 = [[UIImageView alloc]initWithFrame:CGRectMake(640, 0, 320, 480)];
    
    p_w_picpathView1.p_w_picpath = [UIImage p_w_picpathNamed:@"IMG_0242.JPG"];
    p_w_picpathView2.p_w_picpath = [UIImage p_w_picpathNamed:@"IMG_0243.JPG"];
    p_w_picpathView3.p_w_picpath = [UIImage p_w_picpathNamed:@"IMG_0244.JPG"];
    _scrollView.contentInset = UIEdgeInsetsMake(-HIGHTOFNVBAR, 0, 0, 0);
    
    self.navigationController.toolbar.translucent = YES;
    
    self.navigationController.navigationBar.translucent = YES;
    
    
    
    _scrollView.delegate = self;
    
    NSLog(@"%@",NSStringFromCGRect(p_w_picpathView2.frame));
    
    [_scrollView addSubview:p_w_picpathView1];
    [_scrollView addSubview:p_w_picpathView2];
    [_scrollView addSubview:p_w_picpathView3];
}
- (void)tap:(UITapGestureRecognizer *)tap
{
    static int i = 0;
    if (i%2 == 0) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        [self.navigationController setToolbarHidden:YES animated:YES];
        _scrollView.contentInset = UIEdgeInsetsMake(0, 0, HIGHTOFTOOLBAR, 0);
    }
    else
    {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        [self.navigationController setToolbarHidden:NO animated:YES];
        _scrollView.contentInset = UIEdgeInsetsMake(0, 0, -HIGHTOFTOOLBAR, 0);
    }
    i++;
}

使用UIScrollerView的contentInset屬性對UIScrollerView進行擴展即可

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI