温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

UINavigationController+UIScrollView内容视图全屏显示的方法

发布时间:2020-07-22 21:17:45 阅读:1907 作者:NetworkAD 栏目:开发技术
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

我在程序开发时发现,将UINavigationController+UIScrollView组合起来使用时,我将UIImageView放入UIScrollView时,UIImageView并不是按照我预想的那样,以UIScrollView的顶点作为视图添加的位置,这是由于UINavigationController在添加了导航栏以后,将会以导航栏下方作为UIScrollView的原点位置,有时候我们想完全显示该视图的内容,解决方法,看下面这个程序

#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(00320480)];
    
    
    _scrollView.contentSize = CGSizeMake(9600);
    
    _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(00320480)];
    UIImageView *p_w_picpathView2 = [[UIImageView alloc]initWithFrame:CGRectMake(3200320480)];
    UIImageView *p_w_picpathView3 = [[UIImageView alloc]initWithFrame:CGRectMake(6400320480)];
    
    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, 000);
    
    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(00, HIGHTOFTOOLBAR, 0);
    }
    else
    {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        [self.navigationController setToolbarHidden:NO animated:YES];
        _scrollView.contentInset = UIEdgeInsetsMake(00, -HIGHTOFTOOLBAR, 0);
    }
    i++;
}

使用UIScrollerView的contentInset属性对UIScrollerView进行扩展即可

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×