程序启动欢迎界面
程序启动
程序启动时间设置
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[NSThread sleepForTimeInterval:5];
return YES;
}
程序启动时是否隐藏状态栏
* info.plist中添加键值对,`Status bar is initially hidden` = `YES`即可
一张图
* 一张图透明度渐变到完全透明到最后消失
* 只需要在rootViewController的viewDidLoad中获取keyWindow并且将要显示的内容加到keyWindow中即可.透明度逐渐减小,最后移除.
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
UIImageView * imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
imageView.image = [UIImage imageNamed:@"101"];
[[UIApplication sharedApplication].keyWindow addSubview:imageView];
[UIView animateWithDuration:2.0 delay:1 options:0 animations:^{
imageView.alpha = 0;
} completion:^(BOOL finished) {
[imageView removeFromSuperview];
}];
}
倒计时,可点击跳过
* 在上面的基础上增加定时器
-(void)setUI{
UIImageView * imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
imageView.image = [UIImage imageNamed:@"101"];
[[UIApplication sharedApplication].keyWindow addSubview:imageView];
[UIView animateWithDuration:2.0 delay:1 options:0 animations:^{
imageView.alpha = 0;
} completion:^(BOOL finished) {
[imageView removeFromSuperview];
}];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeLabel) userInfo:nil repeats:YES];
NSRunLoop * currentRunloop = [NSRunLoop currentRunLoop];
//runloop循环模式要写成NSRunLoopCommonModes 否则如果有滚动的view在这个界面上定时器会停止计时
[currentRunloop addTimer:self.timer forMode:NSRunLoopCommonModes];
}
-(void)changeLabel{
self.time --;
if (self.time < 0) {
NSLog(@"倒计时完成");
[self.timer invalidate];
self.timer = nil;
self.lblName.hidden = YES;
return;
}
self.lblName.text = [NSString stringWithFormat:@"%zds 跳过",self.time];
}
滑动的scrollview
//所需属性
/* 滚动视图 */
@property (strong, nonatomic) UIScrollView * scrollView;
/* 分页 */
@property (strong, nonatomic) UIPageControl * pageControl;
/* 登录按钮 */
@property (strong, nonatomic) UIButton * btnLogin;
首先初始化UI界面
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self setUI];
}
-(void)setUI{
//创建滚动的scrollView
UIScrollView * scrollView = [UIScrollView new];
scrollView.backgroundColor = [UIColor whiteColor];
self.scrollView = scrollView;
scrollView.bounces = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.delegate = self;
scrollView.frame = KScreen_Bounds;
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(KScreen_Width*4, KScreen_Height);
[self.view addSubview:scrollView];
//在scrollview上添加imageView
for (int i = 0; i<4; i++) {
NSString * imageName = [NSString stringWithFormat:@"%zd.jpg",101+i];
UIImage * image = [UIImage imageNamed:imageName];
UIImageView * imageView = [UIImageView new];
CGFloat y = 0;
CGFloat w = KScreen_Width;
CGFloat h = KScreen_Height;
CGFloat x = 0 + KScreen_Width * i;
imageView.frame = CGRectMake(x, y, w, h);
imageView.image = image;
[scrollView addSubview:imageView];
//在最后一页上添加登录按钮
if (i == 3) {
//添加点击进入button
UIButton * btnLogin = [UIButton new];
self.btnLogin = btnLogin;
btnLogin.frame = CGRectMake(3 * KScreen_Width + (KScreen_Width - 200)/2.0, KScreen_Height - 94, 200, 30);
[btnLogin setTitle:@"点击进入" forState:UIControlStateNormal];
[btnLogin addTarget:self action:@selector(changeRootVc) forControlEvents:UIControlEventTouchUpInside];
btnLogin.backgroundColor = [UIColor blueColor];
btnLogin.layer.cornerRadius = 5;
btnLogin.layer.masksToBounds = YES;
[scrollView addSubview:btnLogin];
}
}
//添加pageControl到self.view上
UIPageControl * pageControl = [[UIPageControl alloc] init];
self.pageControl = pageControl;
pageControl.numberOfPages = 4;
pageControl.frame = CGRectMake((KScreen_Width - 200)/2.0, KScreen_Height - 64, 200, 30);
[self.view addSubview:pageControl];
}
点击登录切换根控制器
#pragma mark - 更改根控制器
-(void)changeRootVc{
[UIView animateWithDuration:2.0 delay:0 options:UIViewAnimationOptionLayoutSubviews animations:^{
self.scrollView.alpha = 0;
} completion:^(BOOL finished) {
[self pushToRootVc];
}];
}
-(void)pushToRootVc{
UIViewController * vc = [UIViewController new];
vc.view.frame = KScreen_Bounds;
vc.view.backgroundColor = [UIColor orangeColor];
[UIApplication sharedApplication].keyWindow.rootViewController = vc;
}
//停止滚动后设置pageControl的页码
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
CGFloat offset = scrollView.contentOffset.x;
int currentPage = (int)(offset / KScreen_Width);
self.pageControl.currentPage = currentPage;
}
流媒体动画(视频)
- 程序启动播放视频,视频播放完毕进入主界面
- http://blog.youkuaiyun.com/alex_birdlion/article/details/52883540