xcode10.1版本 launchScreen.storyboard 没有控件拖入的页面了?

830 阅读1分钟

之前版本有,直接拖入UIImageView 放入 并将图片命名好,然后在general页面的launch images sourc 设置一下,就可以实现启动页,非常方便快捷。 当然,也可以使用代码设置启动页与广告页 广告页直接在APPDelegate.m直接写 代码如下: //获取中心点的xy坐标 float y = [UIScreen mainScreen].bounds.size.height/2; float x = [UIScreen mainScreen].bounds.size.width/2;

// 随机图片
NSArray * nameArr = @[@"启动1.jpg",@"启动2.jpg"];

int t=arc4random()%nameArr.count;

//创建展示动画的imageView
self.imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.imageView.center = CGPointMake(x, y);
self.imageView.userInteractionEnabled = YES;
self.imageView.image = [UIImage imageNamed:nameArr[t]];
[self.window addSubview:self.imageView];
[self.window bringSubviewToFront:self.imageView];
//添加一个跳过按钮
self.skipButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
self.skipButton.frame = CGRectMake(2*x - 80, 40, 70, 25);
self.skipButton.layer.cornerRadius = 12.5;
self.skipButton.titleLabel.font = [UIFont systemFontOfSize:13];
[self.skipButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
self.skipButton.backgroundColor = [UIColor grayColor];
[self.skipButton addTarget:self action:@selector(skipAction:) forControlEvents:(UIControlEventTouchUpInside)];
[self.window addSubview:self.skipButton];
//跳过按钮的倒计时
__block int32_t timeOutCount=timeIntence;
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1ull * NSEC_PER_SEC, 0);
dispatch_source_set_event_handler(timer, ^{
    OSAtomicDecrement32(&timeOutCount);
    if (timeOutCount == 0) {
        NSLog(@"timersource cancel");
        dispatch_source_cancel(timer);
    }
    [self.skipButton setTitle:[NSString stringWithFormat:@"%d 跳过",timeOutCount+1] forState:(UIControlStateNormal)];
});
dispatch_source_set_cancel_handler(timer, ^{
    NSLog(@"timersource cancel handle block");
});
dispatch_resume(timer);
//图片放大动画
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:timeIntence];

// self.imageView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.5f, 1.5f); [UIView commitAnimations]; //图片消失动画 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeIntence * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [UIView animateWithDuration:2 animations:^{ self.imageView.alpha = 0; self.skipButton.alpha = 0; }]; }); //所有动画完成,删除图片和按钮 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((timeIntence + 1.0) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.imageView removeFromSuperview]; [self.skipButton removeFromSuperview]; });

//点击跳过按钮,删除图片和按钮

-(void)skipAction:(UIButton*)sender{ [self.imageView removeFromSuperview]; [self.skipButton removeFromSuperview]; }