如何为APP添加满屏启动页

如何为APP添加满屏启动页,第1张

1、首先,我们创建一个布局splash.xml;

[html] view plain copy print?

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<ImageView

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:scaleType="fitXY"

android:src="@drawable/splash">

</ImageView>

</LinearLayout>

2、再者,创建一个新类SplashActivity.java;

[java] view plain copy print?

public class SplashActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState)

requestWindowFeature(Window.FEATURE_NO_TITLE)

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)

setContentView(R.layout.splash)

Handler hd = new Handler()

hd.postDelayed(new splashhandler(), 800)

}

class splashhandler implements Runnable {

public void run() {

startActivity(new Intent(getApplication(), MainActivity.class))

SplashActivity.this.finish()

}

}

}

3、在manifest中配置我们的启动入口;

[html] view plain copy print?

<activity android:name="x.x.x.SplashActivity"

android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"

android:label="@string/app_name"

android:launchMode="singleTask"

android:screenOrientation="landscape" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />

</intent-filter>

</activity>

最后不要忘了要首屏的图片资源drawable/splash.png;

综上,我们APP的启动页已经做好了。雷达下载更专业。

此处 是自己封装了一个独立的引导页,在任何项目中均可独立引用

首先看.h

[objc] view plain copy

<span style="color:#666666">#import <UIKit/UIKit.h>

/**

* App首次开机引导页

*/

@interface GuideView : UIScrollView<UIScrollViewDelegate>

@end</span><span style="color:#ff4647">

</span>

接着.m

[objc] view plain copy

#import "GuideView.h"

/**

* 引导页张数

*/

#define DEF_GUIDE_COUNT 3

@implementation GuideView

- (id)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame]

if (self)

{

self.bounces=NO

self.contentSize = CGSizeMake(DEF_WIDTH(self)*DEF_GUIDE_COUNT, DEF_HEIGHT(self))

self.backgroundColor = [UIColor blackColor]

self.showsHorizontalScrollIndicator = NO

self.pagingEnabled = YES

self.delegate=self

self.backgroundColor = [UIColor clearColor]

for (int i=0i<DEF_GUIDE_COUNTi++)

{

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(DEF_SCREEN_WIDTH*i, 0, DEF_SCREEN_WIDTH,DEF_SCREEN_HEIGHT)]

[imageView setBackgroundColor:[UIColor redColor]]

[imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Guide%d",i]]]

if ([UIScreen mainScreen].bounds.size.height == 480) {

[imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Guide%d-480",i]]]

}

[self addSubview:imageView]

if (i==2) {

UIButton*button = [UIButton buttonWithType:UIButtonTypeCustom]

button.frame = CGRectMake(0,0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)

button.alpha = 0.5

[button addTarget:self action:@selector(beginClick) forControlEvents:UIControlEventTouchUpInside]

imageView.userInteractionEnabled = YES

[imageView addSubview:button]

}

}

}

return self

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

if (scrollView.contentOffset.x>DEF_SCREEN_WIDTH*3+20) {

[UIView animateWithDuration:0.3 animations:^{

self.alpha = 0.0

} completion:^(BOOL finished) {

[self removeFromSuperview]

}]

}

}

#pragma mark - 点击事件

- (void)beginClick

{

self.userInteractionEnabled = NO

[UIView animateWithDuration:0.3 animations:^{

self.alpha = 0.0

} completion:^(BOOL finished) {

[self removeFromSuperview]

}]

}

引导页上 有的是点击的,有的是需要滑动进入主页的,这两个根据自己的需求来,例子中这两种情况都满足,具体的还得根据自己的需求来,

使用方法也十分简单

[objc] view plain copy

//引导页

if (![DEF_PERSISTENT_GET_OBJECT(@"showGuide") boolValue])

{

[self makeui]

DEF_PERSISTENT_SET_OBJECT([NSNumber numberWithBool:YES], @"showGuide")

GuideView *guide = [[GuideView alloc] initWithFrame:self.window.bounds]

[self.window addSubview:guide]

}

/**

*

取出永久存储的对象

*

* @param key所需对象对应的key

* @return key所对应的对象

*/

#define DEF_PERSISTENT_GET_OBJECT(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]

这是我自己定义的一个宏 用来本地化的

现在大部分APP都会有一个倒计时启动页,用来展示广告,分享一种实现方式,原理其实很简单,就是在程序启动时从后台请求图片和广告数据,存入本地,然后在第二次打开APP的时候去展示,点击启动图可以进入一个webView或者其他自定义的页面展示数据,右上角(或者其他任意位置)放一个带倒计时的跳过按钮,可以直接跳过

新建一个类,逻辑放在在load方法中,所以这个类不用被调用,可以做到无注入

类里边包含的属性

在init方法中注册APP启动的通知

检测启动图数据是否存在以及展示启动图的逻辑:

点击启动图的时候

点击跳过按钮的时候,隐藏启动图

ZCQGStartViewSourceManager 是用来管理启动图数据的类,提供了几个方法


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11739770.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存