<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