主要是写登录图
- 如果现在不明白当时说这句话的意思了,可以去搜搜百度云app,看看他们的登录效果,现在要做的就是实现那种效果(一开始一张图片,后来出现第二张图片(第二张图片实时变化))
原理
-
在LaunchScreen.storyboard中放一张底图,然后在控制器中获取到LaunchScreen的VC上的view,直接在view上再添加一张需要根据条件展示的图片,最后把view添加在控制器的view上就可以
-
我语言表达能力差,还是看代码吧
- (void)viewDidLoad {
[super viewDidLoad];
UIViewController *viewController = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LaunchScreen"];
UIView *launchView = viewController.view;
UIImageView * Imageview= [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
Imageview.image = [UIImage imageNamed:@"baidu2"];
[launchView addSubview:Imageview];
[self.view addSubview:launchView];
[UIView animateWithDuration:6.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
// launchView.layer.transform = CATransform3DRotate(CATransform3DIdentity, M_PI_4, 1.5f, 1.5f, 1.5f);
launchView.transform = CGAffineTransformMakeTranslation(0.0f, 0.1f);
} completion:^(BOOL finished) {
UIImageView *imgViewAd = [[UIImageView alloc] init];
imgViewAd.frame = [UIScreen mainScreen].bounds;
imgViewAd.image = [UIImage imageNamed:@"me"];
[[UIApplication sharedApplication].keyWindow addSubview:imgViewAd];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView animateWithDuration:.25
animations:^{
imgViewAd.alpha = 0.0f;
}
completion:^(BOOL finished) {
[imgViewAd removeFromSuperview];
}];
});
[launchView removeFromSuperview];
}];
}
- 代码如上
补充
最后那个动画方法,好像里面不设置下launchView的形变,就直接不显示launchView上后添加的图片(其实是时间太快,我们没有来得及看到),所以我想了这个笨方法,设置下LaunchView的形变,不明显的形变
-
3D和2D:3D是在layer上设置的,2D是在view上直接添加的,他们原理上和方法上还是很相同的
-
上面的代码中第二张图片可以网络获取,这样就能做到实时更新了
网友评论