你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS 實現引導頁

iOS 實現引導頁

編輯:IOS開發綜合

效果圖明天更新, 今天csdn維護.
直接上代碼(簡簡單單)
創建一個控制器

.h
@protocol selectDelegate 
- (void)click;
@end
@interface XTGuidePagesViewController : UIViewController
@property (nonatomic, strong) UIButton *btnEnter;
// 初始化引導頁
- (void)initWithXTGuideView:(NSArray *)images;
// 版本信息判斷
- (BOOL)isShow;
@property (nonatomic, assign) id delegate;
// 創建單利類
+ (instancetype)shareXTGuideVC;
.m
- (void)initWithXTGuideView:(NSArray *)images
{
    UIScrollView *gui = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, s_w, s_h)];
    gui.pagingEnabled = YES;
    // 隱藏滑動條
    gui.showsHorizontalScrollIndicator = NO;
    gui.showsVerticalScrollIndicator = NO;
    // 取消反彈
    gui.bounces = NO;
    for (NSInteger i = 0; i < images.count; i ++) {
        [gui addSubview:({
            self.btnEnter = [UIButton buttonWithType:UIButtonTypeCustom];
            self.btnEnter.frame = CGRectMake(s_w * i, 0, s_w, s_h);
            [self.btnEnter setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];;
            self.btnEnter;
        })];

        [self.btnEnter addSubview:({
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setTitle:@"點擊進入" forState:UIControlStateNormal];
            btn.frame = CGRectMake(s_w * i, s_h - 60, 100, 40);
            btn.center = CGPointMake(s_w / 2, s_h - 60);
            btn.backgroundColor = [UIColor lightGrayColor];
            [btn addTarget:self action:@selector(clickEnter) forControlEvents:UIControlEventTouchUpInside];
            btn;
        })];
    }
    gui.contentSize = CGSizeMake(s_w * images.count, 0);
    [self.view addSubview:gui];
}

單利

+ (instancetype)shareXTGuideVC
{
    static XTGuidePagesViewController *x = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        x = [[XTGuidePagesViewController alloc] init];
    });
    return x;
}
- (void)clickEnter
{
    if (self.delegate != nil && [self.delegate respondsToSelector:@selector(click)]) {
        [self.delegate click];
    }
}
- (BOOL)isShow
{
    // 讀取版本信息
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *localVersion = [user objectForKey:VERSION_INFO_CURRENT];
    NSString *currentVersion =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSLog(@"L ===%@", localVersion);
    NSLog(@"C ===%@", currentVersion);
    if (localVersion == nil || ![currentVersion isEqualToString:localVersion]) {
        [self saveCurrentVersion];
        return YES;
    }else
    {
        return NO;
    }
}
// 保存版本信息
- (void)saveCurrentVersion
{
    NSString *version =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:version forKey:VERSION_INFO_CURRENT];
    [user synchronize];
}

在app delegate中調用

NSArray *images = @[@"1", @"2", @"3"];
    if ([[[XTGuidePagesViewController alloc] init] isShow]) {
        self.window.rootViewController = [XTGuidePagesViewController shareXTGuideVC];
        [[XTGuidePagesViewController shareXTGuideVC] initWithXTGuideView:images];
        [XTGuidePagesViewController shareXTGuideVC].delegate = self;
    }else{
        [self click];
    }
- (void)click
{
    ViewController *vc = [[ViewController alloc] init];
    self.window.rootViewController = vc;
    [self.window.layer transitionWithAnimType:TransitionAnimTypeRamdom subType:TransitionSubtypesFromRamdom curve:TransitionCurveRamdom duration:2.0f];
}

還會持續更新

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved