日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

制作引导页[3]

發布時間:2025/3/20 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 制作引导页[3] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

制作引導頁[3]

第三種方法是將整個引導頁寫到一個controller中,是通用性最高的一種寫法:)

效果:

源碼:

AppDelegate.m

// // AppDelegate.m // Show // // Copyright (c) 2014年 Y.X. All rights reserved. //#import "AppDelegate.h" #import "WelcomeViewController.h"@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];// 接管控制器self.window.rootViewController = [WelcomeViewController new];self.window.backgroundColor = [UIColor whiteColor];// 讓視圖可見[self.window makeKeyAndVisible];return YES; }@end
WelcomeViewController.m
// // WelcomeViewController.m // Show // // Copyright (c) 2014年 Y.X. All rights reserved. //#import "WelcomeViewController.h" #import "RootViewController.h"@interface WelcomeViewController ()@end@implementation WelcomeViewController- (void)viewDidLoad {[super viewDidLoad]; }- (void)viewDidAppear:(BOOL)animated {[self scrollView]; }- (void)scrollView {CGRect rect = self.view.window.bounds;CGFloat width = rect.size.width;CGFloat height = rect.size.height;// 初始化scrollViewUIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:rect];scrollView.pagingEnabled = YES;scrollView.tag = 0x77;scrollView.contentSize = CGSizeMake(width * 3, height);// 添加一些控件for (int i = 0; i < 3; i++){UIView *tmp = [[UIView alloc] initWithFrame:CGRectMake(i*width, 0, width, height)];tmp.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1];if (i == 2){YXButton *button = [[YXButton alloc] initWithFrame:CGRectMake(0, 0, 140, 30)];button.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin"size:20.f];button.layer.cornerRadius = 3.f;[button addTarget:selfaction:@selector(buttonEvent:)forControlEvents:UIControlEventTouchUpInside];[button setBackgroundColor:[UIColor blackColor]highlightedBackgroundColor:[UIColor whiteColor]];[button setNormalTitleColor:[UIColor whiteColor]highlightedTitleColor:[UIColor blackColor]disabledTitleColor:nil];[button setNormalTitle:@"YouXianMing"highlightedTitle:@"YouXianMing"disabledTitle:@"YouXianMing"];button.center = self.view.window.center;[tmp addSubview:button];}[scrollView addSubview:tmp];}// 添加到UIWindow當中[self.view.window addSubview:scrollView]; }- (void)buttonEvent:(UIButton *)button {UIScrollView *scrollView = (UIScrollView *)[self.view.window viewWithTag:0x77];scrollView.userInteractionEnabled = NO;// 動畫[UIView animateWithDuration:2.0 animations:^{scrollView.alpha = 0.f;} completion:^(BOOL finished) {// 從UIWindow上移除這個scrollView[scrollView removeFromSuperview];// 切換視圖控制器self.view.window.rootViewController = [RootViewController new];}]; }@end
RootViewController.m
// // RootViewController.m // Show // // Copyright (c) 2014年 Y.X. All rights reserved. //#import "RootViewController.h"@interface RootViewController ()@end@implementation RootViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor whiteColor];[UIView animateWithDuration:2 animations:^{self.view.backgroundColor = [UIColor blackColor];}]; }@end

幾個需要注意的地方:

動畫結束后要切換視圖控制器

過渡更自然

?

總結:

這幾篇教程制作引導頁的核心都是在UIWindow上加載視圖或者視圖控制器,就是這么容易哦:)

總結

以上是生活随笔為你收集整理的制作引导页[3]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。