欢迎界面iOS——初学者福利

14 篇文章 0 订阅

<p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 16px;"><span style="font-size: 18px;">                              ”<span style="color:#ff0000;">欢迎界面“设计到的知识点</span></span></span></p><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 18px;"><span style="color:#ff0000;">          内容:四张图片,完成滑动,点击最后一张图片上的按钮实现页面跳转;</span></span></p><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 16px;"><span style="font-size: 18px;">
</span></span></p><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 16px;"><span style="font-size: 18px;">1导航控制器UINavigationController</span></span></p><blockquote><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 16px;"><span style="font-size: 18px;">1.1 配置导航栏</span></span></p><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 16px;"><span style="font-size: 18px;">     通过设置navigationItem的属性完成</span></span></p><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 16px;"><span style="font-size: 18px;">     左右:类型:UIBarButtonItem类型</span></span></p></blockquote><blockquote><blockquote><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 16px;"><span style="font-size: 18px;">leftBarButtonItem</span></span></p></blockquote><blockquote><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 16px;"><span style="font-size: 18px;">rightBarButtonItem</span></span></p></blockquote><span style="font-size: 18px; line-height: 1.5;">     中:title titleView</span></blockquote><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 18px; line-height: 1.5; color: rgb(0, 153, 0);">注意知识点:</span></p><blockquote><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 18px; line-height: 1.5; color: rgb(0, 153, 0);">    导航栏高度:包含状态栏(status Bar)64个点,上边的电池管理器的那条状态栏  高度是20个点</span></p></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">1.2配置栏toolBar</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">默认隐藏,设置</span></blockquote><blockquote><span style="font-size: 18px; line-height: 27px;">navigationController.toolBarButtonItemHidden=NO,显示</span></blockquote><blockquote><span style="font-size: 18px; line-height: 27px;"></span><p class="p1" style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;">navigationController.navigationBarHidden = YES;隐藏</p><span style="font-size: 18px; line-height: 1.5;">工具条中的内容通过控制器的 toolBarItems的属性</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">工具条中只能容纳UIBarButtonitem类型的实例</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">1.3导航控制器的原理</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">    导航控制器有一个属性,叫做viewContollers,这是一个数组类型的属性,依靠这个属性来存储管理多个控制器,并且这个数组在管理多个数据时,采用的时“栈”的管理方法,</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">   <span style="color: rgb(0, 153, 0);"> 栈:先进后出,后进先出</span></span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5; color: rgb(0, 153, 0);">    队列:先进先出,</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">1.4</span><span style="font-size: 18px; line-height: 1.5;">属性的作用域范围</span></blockquote><blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">1.1.跟内容有关的</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">    navigationItem的左中右</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">    toolBarItems中的内容</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">    设置有效范围只在当前VC</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;"> 1.2 跟显示隐藏有关的</span></blockquote><blockquote><span style="font-size: 18px; line-height: 27px;">设置有效范围会在所有VC的</span></blockquote></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">1.5  多导航控制器的切换</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">导航控制器是继承自UIViewController的,所以,导航控制器也有presentViewController的方法,于是,两个导航控制器之间可以用present实现切换</span></blockquote><blockquote><span style="font-size: 18px; line-height: 1.5;">
</span></blockquote><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 18px; line-height: 1.5;">2滚动视图UIScrollView</span></p><blockquote><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 18px; line-height: 1.5;"> 继承自UIView,除了可以做容器使用,可以设置超出它自己尺寸的内容区域,并且,这些超出方位的内容,可以通过左右上下滑动的手势来查看,</span></p></blockquote><blockquote><p style="word-wrap: break-word; margin-top: 5px; margin-bottom: 5px;"><span style="font-size: 18px; line-height: 1.5;">使用要点:</span></p></blockquote><blockquote><blockquote style="font-family: 'sans serif', tahoma, verdana, helvetica; line-height: 18px;"><span style="font-size: 18px; line-height: 1.5;">》需要向滚动视图内添加要展示的子视图</span></blockquote><blockquote style="font-family: 'sans serif', tahoma, verdana, helvetica; line-height: 18px;"><span style="font-size: 18px; line-height: 1.5;">》一定要设置滚动视图的frame</span></blockquote><blockquote style="font-family: 'sans serif', tahoma, verdana, helvetica; line-height: 18px;"><span style="font-size: 18px; line-height: 1.5;">》一定要设置滚动视图的内容的尺寸contenSize</span></blockquote><div><span style="font-size: 18px; line-height: 1.5;">
</span></div><span style="font-family: 'sans serif', tahoma, verdana, helvetica; font-size: 18px; line-height: 1.5;"></span></blockquote>


<span style="font-family: Arial, Helvetica, sans-serif;">@interface WelcomeViewController ()<UIScrollViewDelegate></span>

@property(nonatomic,strong)UIPageControl *pageControl;

@end

@implementation WelcomeViewController

- (void)viewDidLoad {
    [superviewDidLoad];
    [selfsetupScrollView];
    [selfsetupPageControl];
}

// 定制滚动视图
-(void)setupScrollView
{
    // 创建滚动视图
    UIScrollView *sv = [[UIScrollViewalloc]init];
    
    // 为了捕获滚动视图与用户的交互,需要设置代理
    sv.delegate =self;
    
    // 设置边缘不能弹跳
    sv.bounces =NO;
    
    // 设置滚动视图整页滚动
    sv.pagingEnabled =YES;
    
    // 设置水平滚动条不可见
    sv.showsHorizontalScrollIndicator =NO;
    
    // 设置滚动视图的可见区域
    sv.frame =self.view.bounds;
    
    // 设置contentSize
    sv.contentSize =CGSizeMake(sv.bounds.size.width*4, sv.bounds.size.height);

    // 添加子视图
    for (NSInteger i=0; i<4; i++)
    {
        UIImageView *imageView = [[UIImageViewalloc]init];
    //图的大小设置
        imageView.frame =CGRectMake(sv.bounds.size.width*i,0, sv.bounds.size.width, sv.bounds.size.height);
        
        NSString *fileName = [NSStringstringWithFormat:@"welcome%ld.png",i+1];
        imageView.image = [UIImageimageNamed:fileName];
        [sv addSubview:imageView];
        
        //如果是最后一幅图片,则向其中添加一个按钮
        if (i==3) {
            [selfsetupEnterButton:imageView];
        }
    }
    // 添加滚动视图到控制器的view中
    [self.viewaddSubview:sv];
}

// 定制屏幕下方的圆点
-(void)setupPageControl
{
    //创建pageControl
    UIPageControl *pageControl = [[UIPageControlalloc]init];
    self.pageControl = pageControl;
    
    //设置frame
    pageControl.frame =CGRectMake(0,self.view.bounds.size.height-50,self.view.bounds.size.width,30);
    
    //设置圆点的个数
    pageControl.numberOfPages =4;
    
    //设置圆点的颜色
    pageControl.pageIndicatorTintColor = [UIColorblackColor];
    
    //设置选中的圆点的颜色
    pageControl.currentPageIndicatorTintColor = [UIColorredColor];
    
    //设置某个圆点被选中
    //pageControl.currentPage = 3;
    
    //设置圆点不能与用户交互
    pageControl.userInteractionEnabled =NO;
    
    //添加到控制器的view中,盖在滚动视图之上
    [self.viewaddSubview:pageControl];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //获取滚动位置的偏移量
    CGPoint point = scrollView.contentOffset;
    //计算偏移量是滚动视图宽度的整数倍
    //为了在超过一半时,就自动是下一个圆点
    //通过round函数四舍五入即可
    self.pageControl.currentPage =round(point.x/scrollView.bounds.size.width);
}

// 配置点击进入程序的按钮
-(void)setupEnterButton:(UIImageView *)iv
{
    //打开iv的用户交互功能,按钮才能响应点击
    iv.userInteractionEnabled =YES;
    
    UIButton *button = [[UIButtonalloc]init];
    button.frame =CGRectMake((iv.bounds.size.width-100)/2, iv.bounds.size.height*0.6,100, 40);
    //button.backgroundColor = [UIColor lightGrayColor];
    [button setTitle:@"进入应用"forState:UIControlStateNormal];
    //配置按钮的边缘
    button.layer.borderWidth =2;
    button.layer.borderColor = [UIColorredColor].CGColor;
    button.layer.cornerRadius =10;
    
    //增加点击事件
    [button addTarget:selfaction:@selector(clickEnterAppButton:)forControlEvents:UIControlEventTouchUpInside];
    [iv addSubview:button];
}

// 点击进入按钮,推出主界面
-(void)clickEnterAppButton:(UIButton *)btn
{
    MainViewController *mainVC = [[MainViewControlleralloc]init];
    
    //更换window的根视图为mainVC
    //欢迎界面不再是根视图以后,就会被系统回收
    
    //获取在main函数中创建过的那个唯一的应用程序对象
    UIApplication *application = [UIApplicationsharedApplication];
    UIWindow *window = application.keyWindow;
    
    //更换根vc
    window.rootViewController = mainVC;
}





@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值