splash screen in mainStory board


AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],@"firstLaunch",nil]];
    return YES;

}

SplashScreenViewController.h

#import <UIKit/UIKit.h>

@interface SplashScreenViewController : UIViewController<UIPageViewControllerDataSource>
//@property (weak, nonatomic) IBOutlet UIImageView *splashImg;
@property (strong, nonatomic) UIPageViewController *pageViewController;

@property (strong, nonatomic) NSArray *pageImages;


@end

SplashScreenViewController.m

#import "SplashScreenViewController.h"
#import "ViewController.h"
#import "AppDelegate.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "AboutSlideImagesViewController.h"
//#import "TabViewController.h"
@interface SplashScreenViewController ()
{
    AppDelegate *appdelegat;
    MPMoviePlayerController*moviePlayer;
    AVPlayer *avPlayer;
    NSString *videoPath;
    UIPageControl *pageControl;
    UIButton*skip;
}
@end
@implementation SplashScreenViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    if([[NSUserDefaults standardUserDefaults]boolForKey:@"firstLaunch"])
    {
        self.pageImages=[[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
        NSLog(@"%@",self.pageImages);
        self.navigationController.navigationBar.hidden=YES;
        
        self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
        self.pageViewController.dataSource = self;
        
        AboutSlideImagesViewController *startingViewController = [self viewControllerAtIndex:0];
        NSArray *viewControllers = @[startingViewController];
        [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
        
        // Change the size of page view controller
        self.pageViewController.view.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
        
        [self addChildViewController:_pageViewController];
        [self.view addSubview:_pageViewController.view];
        [self.pageViewController didMoveToParentViewController:self];
        
        pageControl = [[UIPageControl alloc] init];
        [self.view addSubview:pageControl];
        pageControl.pageIndicatorTintColor = [UIColor whiteColor];
        pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:0.99 green:0.38 blue:0.38 alpha:1.0];
        pageControl.frame = CGRectMake(90,self.view.frame.size.height-50,150,30);
        [pageControl setNumberOfPages:_pageImages.count];
        [self.view bringSubviewToFront:pageControl];
        
        skip=[[UIButton alloc]init];
        skip.frame=CGRectMake(self.view.frame.size.width-80,self.view.frame.size.height-50,50,40);
        [skip setTitle:@"Skip" forState:UIControlStateNormal];
        skip.titleLabel.textAlignment=NSTextAlignmentLeft;
        
        [skip setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [skip addTarget:self action:@selector(playBackFinished) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:skip];
        [[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"firstLaunch"];
        
        
            videoPath = [[NSBundle mainBundle] pathForResource:@"3.720p" ofType:@"mp4"];
                moviePlayer.currentPlaybackRate = 0.5;
    }else
    {
        videoPath = [[NSBundle mainBundle] pathForResource:@"3.720p" ofType:@"mp4"];
        moviePlayer.currentPlaybackRate = 0.5;
        // }
        NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
        moviePlayer.controlStyle=MPMovieControlStyleNone;
        [moviePlayer.view setFrame:self.view.bounds];
        [self.view insertSubview:moviePlayer.view atIndex:0];
        [self.view addSubview:moviePlayer.view];
        
        [moviePlayer play];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playBackFinished) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
        appdelegat = (AppDelegate *)[[UIApplication sharedApplication]delegate];
        [self.navigationController setNavigationBarHidden:YES];
    }
}
-(void)playBackFinished
{
    ViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"vc"];
    [self presentViewController:ViewController animated:YES completion:nil];
    

}

#pragma mark - Page View Controller Data Source

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    NSUInteger index = ((AboutSlideImagesViewController*) viewController).pageIndex;
    [skip setTitle:@"Skip" forState:UIControlStateNormal];
    [pageControl setCurrentPage:index];
    if ((index == 0) || (index == NSNotFound)) {
        return nil;
    }
    
    index--;
    return [self viewControllerAtIndex:index];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    NSUInteger index = ((AboutSlideImagesViewController*) viewController).pageIndex;
    [pageControl setCurrentPage:index];
    
    if (index == NSNotFound) {
        return nil;
    }
    
    index++;
    if (index == [self.pageImages count])
    {
        [skip setTitle:@"Done" forState:UIControlStateNormal];
        return nil;
    }
    return [self viewControllerAtIndex:index];
}
- (AboutSlideImagesViewController *)viewControllerAtIndex:(NSUInteger)index
{
    if (([self.pageImages count] == 0) || (index >= [self.pageImages count])) {
        return nil;
    }
    
    // Create a new view controller and pass suitable data.
    AboutSlideImagesViewController *aboutSlideImagesViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AboutSlideImagesViewController"];
    
    //  aboutSlideImagesViewController.imageFile = [UIImage imageNamed:[self.pageImages objectAtIndex:index]];
    aboutSlideImagesViewController.imageFile = self.pageImages[index];
    aboutSlideImagesViewController.tutorialStg=@"Tutorial";
    aboutSlideImagesViewController.pageIndex = index;
    
    return aboutSlideImagesViewController;
}
-(void)viewDidLayoutSubviews
{
    
    if([[NSUserDefaults standardUserDefaults]boolForKey:@"INTERNET_CONNECTION"])
    {
        
    }else
    {
        if([[NSUserDefaults standardUserDefaults]boolForKey:@"firstLaunch"])
        {
            [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"firstLaunch"];
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"NETWORK ERROR" message:@"Please check internet connection" preferredStyle:UIAlertControllerStyleAlert];
            
            // UIAlertAction * cancelButton = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil];
            UIAlertAction * cancelButton = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
                                            {
                                                //                                [NSThread mainThread];                                                    exit(0);
                                            }];
            [alert addAction:cancelButton];
            [self presentViewController:alert animated:YES completion:nil];
            
        }else
        {
            
        }
    }
}

@end

AboutSlideImagesViewController.h

#import <UIKit/UIKit.h>

@interface AboutSlideImagesViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;


@property NSUInteger pageIndex;

@property NSString *imageFile;
@property NSString*tutorialStg;

@end

AboutSlideImagesViewController.m

#import "AboutSlideImagesViewController.h"
#import "UIImageView+WebCache.h"
@interface AboutSlideImagesViewController ()
@end

@implementation AboutSlideImagesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if ([_tutorialStg isEqualToString:@"Tutorial"])
    {
        self.backgroundImage.image=[UIImage imageNamed:_imageFile];
    }else
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [_backgroundImage sd_setImageWithURL:[NSURL URLWithString:self.imageFile] placeholderImage:[UIImage imageNamed:@"defaulticon.png"] options:SDWebImageRefreshCached];
            //self.backgroundImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_imageFile]]];
        });
    }
    
}
@end

PageViewController.h

#import <UIKit/UIKit.h>
#import "UIImageView+WebCache.h"

@interface PageViewController : UIViewController
@property NSUInteger pageIndex;
@property NSUInteger currentIndex;
//@property NSString *titleText;
@property NSString *imageFile;
@property NSUInteger LastIndex;
//@property (weak, nonatomic) IBOutlet UILabel *pageLBL;
@property (weak, nonatomic) IBOutlet UIImageView *pageImage;
@property (weak, nonatomic) IBOutlet UIButton *pageIMG;
- (IBAction)imageAction:(id)sender;
@property NSAttributedString * titleText;
@property NSString * outletID;
@property NSString * dealTypeID;
@end

PageViewController.m

#import "PageViewController.h"

#import "ViewController.h"
#import "OpinionzAlertView.h"

@interface PageViewController ()<OpinionzAlertViewDelegate>

@end

@implementation PageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSLog(@"self.imageFile : %@",self.imageFile);
    NSURL *url;
    if (![self.imageFile isEqualToString:@""])
    {
        url = [NSURL URLWithString:self.imageFile];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
            
            dispatch_async(dispatch_get_main_queue(), ^{
                // Update the UI
                
                [_pageImage sd_setImageWithURL:[NSURL URLWithString:self.imageFile] placeholderImage:[UIImage imageNamed:@"default_bg_icon.png"] options:SDWebImageRefreshCached];
                
            });
        });
        
        // _pageImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
        //        [_pageImage sd_setImageWithURL:[NSURL URLWithString:self.imageFile] placeholderImage:[UIImage imageNamed:@"default_bg_icon.png"]];
    }
    else
    {
        _pageImage.image = [UIImage imageNamed:@"default_bg_icon.png"];
    }
    
    //    self.pageImage.image = [UIImage imageNamed:self.imageFile];
    
    
    
    /*********** BharathSai_25/03/2016 ***********/
    
    
    
    //    UILabel *address=[[UILabel alloc]init];
    //    address. frame = CGRectMake(0, 120, self.view.frame.size.width-100, 60);
    //    address.backgroundColor= [[UIColor whiteColor]colorWithAlphaComponent:1.6f];
    //    address.attributedText = self.titleText;
    
    
    NSString * stringForAddress =[NSString stringWithFormat:@"%@",_titleText];
    
    NSMutableParagraphStyle *style =  [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.alignment = NSTextAlignmentJustified;
    style.firstLineHeadIndent = 10.0f;
    style.headIndent = 10.0f;
    style.tailIndent = -10.0f;
    
    //     NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:stringForAddress attributes:@{
    //                                                                                                            NSParagraphStyleAttributeName : style}];
    
    // _pageLBL.attributedText = attrText;
    
    //    _pageLBL.attributedText = [NSString stringWithFormat:@"%@",_titleText];
    NSLog(@"_outletID in slider click ViewDidLoad : %@",_outletID);
    
    
    /*********************************************/
    
    //    address.alpha = 0.5;
    //    address.numberOfLines=0;
    //    address.textAlignment=NSTextAlignmentLeft;
    //    [address sizeToFit];
    //    [self.view addSubview:address];
    
    
    //    CAGradientLayer *buttonGradient = [CAGradientLayer layer];
    //    buttonGradient.frame = _pageIMG.bounds;
    //    buttonGradient.colors = [NSArray arrayWithObjects:[UIColor whiteColor],[UIColor blackColor], nil];
    //
    //    //[NSArray arrayWithObjects:
    ////                             (id)[[UIColor colorWithRed:.0
    ////                                                  green:.40
    ////                                                   blue:.80
    ////                                                  alpha:1] CGColor],
    ////                             (id)[[UIColor colorWithRed:.0
    ////                                                  green:.113
    ////                                                   blue:.255
    ////                                                  alpha:1] CGColor],
    //                            // nil];
    ////    [buttonGradient setCornerRadius:backButton.frame.size.width / 2];
    //
    //    buttonGradient.cornerRadius = _pageIMG.layer.cornerRadius;
    //    [_pageIMG.layer addSublayer:buttonGradient];
    //    [_pageIMG bringSubviewToFront:_pageIMG.imageView];
    
    //    [_pageIMG setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:url]] forState:UIControlStateNormal];
    //    [_pageIMG sd_setImageWithURL:url placeholderImage:nil];
    //    self.pageLBL.text = self.titleText;
    
}


- (IBAction)imageAction:(id)sender
{
    NSUserDefaults *login = [NSUserDefaults standardUserDefaults];
    if ([login valueForKey:@"UserID"] != nil)
    {
        if (_pageIndex==0)
        {
            
        }else if(_pageIndex==_LastIndex)
        {

        }else
        {
            NSLog(@"_outletID in slider click : %@",_outletID);
            NSLog(@"DealtypeID in slider click : %@",_dealTypeID);
            
            if ([_dealTypeID isEqualToString:@"5"])
            {

            }
            else if ([_dealTypeID isEqualToString:@"4"])
            {
            }
        }
        
    }else
    {
        if (_pageIndex==0)
        {
            OpinionzAlertView*alert=[[OpinionzAlertView alloc]initWithTitle:nil message:@"You need to login to use this feature" cancelButtonTitle:@"Not Now" otherButtonTitles:@[@"Login"]];
            
            alert.iconType=OpinionzAlertIconSuccess;
            alert.icon=[UIImage imageNamed:@"CB logo.png"];
            alert.delegate=self;
            [alert show];
            
        }else if(_pageIndex==_LastIndex)
        {
            OpinionzAlertView*alert=[[OpinionzAlertView alloc]initWithTitle:nil message:@"You need to login to use this feature" cancelButtonTitle:@"Not Now" otherButtonTitles:@[@"Login"]];
            
            alert.iconType=OpinionzAlertIconSuccess;
            alert.icon=[UIImage imageNamed:@"CB logo.png"];
            alert.delegate=self;
            [alert show];
            
        }else
        {
            NSLog(@"_outletID in slider click : %@",_outletID);
            NSLog(@"DealtypeID in slider click : %@",_dealTypeID);
            
            if ([_dealTypeID isEqualToString:@"5"])
            {

            }
            else if ([_dealTypeID isEqualToString:@"4"])
            {

            }
            
        }
        
    }
    
    
}
- (void)alertView:(OpinionzAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex==0)
    {
        [alertView dismiss];
        
    }
    else if (buttonIndex==1)
    {
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    }
}
@end


FrameWorks 

1. SDWebImage
2.OpinionzAlertview
3.AVFoundation
4.AVKit
5.MediaPlayer

Previous
Next Post »

ConversionConversion EmoticonEmoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng