preface


Advertising pages in the App are more common, let alone novice guide, basically every application must have a novice guide. Although there are more three parties in the package now, SAO Dong still wants to build the wheel by itself. SDLaunch is a guide page with a variety of page types. Including, advertising page type, ** novice guidance type **, GIF background page type, scrolling background page type four forms, basically can meet all the needs of the guide page. Let’s take a look at the usage specifications of SDLunch.


SDLaunch instructions


SDLaunch tripartite main body is SDLaunchViewController SDLaunchViewController is an inheritance in the UIViewController class, the class USES the SDWebImage the three parties, if the project has been imported in SDWeb The Image, please delete the SDLunch SDWebImage SDLaunchWebViewController is a controller for advertising page load. The controller is presented as a modal view. Note that SDLunch is the root view controller that needs to be specified in the AppDelegate code.

❗️❗️ ️ ️ maximum note: If the local image array and the server image array are loaded at the same time, the local image will not take effect. It is recommended to use the local image ~ because the server image may cause lag, and the user experience may deteriorate.

Jump to the App / * * * / – root view controller (void) skipAppRootMainViewController;

*/ @property(nonatomic,strong)UIButton *endButton; */ @property(nonatomic,strong)UIButton;

There are four types of SDLaunchViewController, which we need to specify at initialization. The type is an enumerated value, as shown below. We'll explain the attributes for each page type.Copy the code

Typedef enum {GreenhandLaunchViewController ADLaunchViewController, / / advertising types, / / round figure newbie guide type GifBackgroundLaunchViewController, / / GIF chart background type RollImageLaunchViewController / / scroll picture type} LaunchViewControllerType;



<br>

#### ad-type SDLaunch*** The SDLaunchViewController is a Demo folder that can be used in a project. The first step is to import the SDLaunch folder into the project. Then we need to initialize our SDLaunchViewController in the AppDelegate and set the page type to **ADLaunchViewController**. Since most AD pages are dynamic, we need to specify the URL of the AD image as well as the URL of the AD page, and finally the root graph controller. The specific code is shown below.Copy the code
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];

SDLaunchViewController *vc = [[SDLaunchViewController alloc]initWithMainVC:[[ViewController alloc]init] viewControllerType:ADLaunchViewController];

vc.imageURL = @"http://pic.qiantucdn.com/58pic/17/80/57/94s58PICA7j_1024.jpg";

vc.adURL = @"http://www.jianshu.com/users/e39da354ce50/latest_articles";
self.window.rootViewController = vc;

[self.window makeKeyAndVisible];
Copy the code
The renderings are shown below. [](http://upload-images.jianshu.io/upload_images/1396375-ddb59d2b61e18de8.gif? Other attributes of the imageMogr2/ Auto-orient/Strip) **ADLaunchViewController** type are shown below, and we can customize special AD pages to our own needs.Copy the code

/ / @property(nonatomic,strong)NSString *titleString;

*/ @property(nonatomic,assign)BOOL isSkip;


>  ###### ❗️❗ college ###### notice that the AD type SDLaunch may have a delay if it loads the server advertisement image, so the placeholder should be set as the image of the guide image, so that the user experience is improved, but the backward seconds may be reduced when it is used for the first time.! [Placeholder Settings](http://upload-images.jianshu.io/upload_images/1396375-1b569d5cfbb44dda.png? imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) <br>#### Novice guided type SDLaunch* * * Newbie guide type of SDLaunch is mainly used for the first time into the App using, type enumeration values for GreenhandLaunchViewController * * * *, including novice directs our initialization steps and advertisement type is the same, but we need the incoming image is an array type, if it is local pictures , we pass in the imageNameArray (imageNameArray), if it is a server-side image, we pass in the imageURL string array (imageURLArray). One thing to note here is that when both are passed in, the default is to use an array of image urls on the server side. The specific code is shown below.Copy the code
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor whiteColor]; SDLaunchViewController *vc = [[SDLaunchViewController alloc]initWithMainVC:[[ViewController alloc]init] viewControllerType:GreenhandLaunchViewController]; Vc. ImageNameArray = @[@" tutorial 1",@" tutorial 2"]; self.window.rootViewController = vc; [self.window makeKeyAndVisible];Copy the code
The renderings are shown below. [](http://upload-images.jianshu.io/upload_images/1396375-822390574b1d73db.gif? ImageMogr2 / Auto-orient/Strip) of course, there are additional attributes for the new guide, such as **endButton**(access controller button) and **pageControl**(page tag) that we can customize.#### GIF background type of SDLaunch*** There are many times when we need to customize a page with a GIF background, not only in the launch page, but also in SDLaunch's **GifBackgroundLaunchViewController * * type is used to complete this task. In this type we need to specify the local name of the GIF image or the URL of the image. Also this type declares **frontGifView(translucent)** This property is used to add various controls to the page. For example, if we create a GIF boot page, we can go to **frontGif> Note: The gifImageName attribute does not need to be assigned with the **.gif** suffix.Copy the code
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor whiteColor]; SDLaunchViewController *vc = [[SDLaunchViewController alloc]initWithMainVC:[[ViewController alloc]init] viewControllerType:GifBackgroundLaunchViewController]; Vc. gifImageName = @" GIF "; / / network GIF picture URL vc. The gifImageURL = @ "http://image76.360doc.com/DownloadImg/2014/07/1510/43430258_28"; UILabel *titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 100,[UIScreen mainScreen].bounds.size.width , 60)]; titleLable.font = [UIFont fontWithName:@"Helvetica-Bold" size:20]; titleLable.textColor = [UIColor whiteColor]; titleLable.textAlignment = NSTextAlignmentCenter; Titlelable. text = @" "; titlelable. text = @" "; [vc.frontGifView addSubview:titleLable]; self.window.rootViewController = vc; [self.window makeKeyAndVisible];Copy the code
The renderings are shown below. [](http://upload-images.jianshu.io/upload_images/1396375-3ca2643fe51ec192.gif? imageMogr2/auto-orient/strip) <br>#### Scroll image type SDLaunch* * * in the App now has a lot of page background image is a picture of a scroll, SDLaunch RollImageLaunchViewController * * * * type is the picture scroll, which we need to do is also need to specify the image local name or URL. Here we take the startup diagram as an example, with the code shown below.Copy the code
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor whiteColor]; SDLaunchViewController *vc = [[SDLaunchViewController alloc]initWithMainVC:[[ViewController alloc]init] viewControllerType:RollImageLaunchViewController]; Vc. rollImageName = @" scroll image.jpeg "; UILabel *titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 100,[UIScreen mainScreen].bounds.size.width , 60)]; titleLable.font = [UIFont fontWithName:@"Helvetica-Bold" size:20]; titleLable.textColor = [UIColor whiteColor]; titleLable.textAlignment = NSTextAlignmentCenter; Titlelable. text = @" "; titlelable. text = @" "; [vc.frontRollView addSubview:titleLable]; self.window.rootViewController = vc; [self.window makeKeyAndVisible];Copy the code
The renderings are shown below.(The renderings may lag because the image size can only be set to 30FPS, so some lag)! [](http://upload-images.jianshu.io/upload_images/1396375-650598d9f11279f0.gif? imageMogr2/auto-orient/strip) <br>##### SDLaunch core code explanation of scrolling image typeThe other three types of core code is relatively simple, the core way of rolling picture type is to realize the rolling picture, the house is to use a timer and change the imageView frame to achieve, the whole part of the implementation is mainly in the **rollImageAction this method to achieve. In this method, we need to determine whether the x coordinate exceeds the maximum allowed range, if so, then change the Boolean value isReverse, that is, change the calling method. The same is true in the reverse approach. The specific code is shown below.Copy the code

int rollX = 0; bool isReverse = NO; // Reverse roll -(void)rollImageAction{

if (rollX-1 >(SDMainScreenBounds.size.width-SDMainScreenBounds.size.height* _rollImage.size.width/_rollImage.size.height) &&! isReverse) { rollX = rollX-1; _rollImageView.frame = CGRectMake(rollX, 0,SDMainScreenBounds.size.height* _rollImage.size.width/_rollImage.size.height, SDMainScreenBounds.size.height); }else{ isReverse = YES; } if (rollX+1 < 0 &&isReverse) { rollX = rollX +1; _rollImageView.frame = CGRectMake(rollX, 0,SDMainScreenBounds.size.height* _rollImage.size.width/_rollImage.size.height, SDMainScreenBounds.size.height); }else{ isReverse = NO; }Copy the code

}

Of course, before doing this, we need to determine the aspect ratio of the image, because the image moves horizontally, not vertically and fills the screen. So if the width of the image is greater than the height, then the effect is impossible to achieve, we need to make a judgment. The whole is implemented in **addRollImageAndTimer**, for the network picture and local picture fetch the method of timing is different, because the network load is delayed.Copy the code

-(void)addRollImageAndTimer{

if (_rollImage ! Height > _rollimage.size.width) {NSLog(@"Error: scroll image height is higher than width, cannot scroll horizontal!" ); }else{ _rollImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,SDMainScreenBounds.size.height* _rollImage.size.width/_rollImage.size.height, SDMainScreenBounds.size.height)]; _rollImageView.image = _rollImage; Self. RollTimer = [NSTimer scheduledTimerWithTimeInterval: 0.05 target: self selector: @ the selector (rollImageAction) userInfo:nil repeats:YES]; [self.view addSubview:_rollImageView]; if (! _hideEndButton) { [self.frontRollView addSubview:self.endButton]; _endButton.tintColor = [UIColor blueColor]; } [self.view addSubview:self.frontRollView]; [self.rollTimer fire]; }Copy the code

<br>

#### SDLaunchDemo usage* * *# # # - > [SDLaunchDemo portal 🚪] (https://github.com/wang82426107/SDLaunchDemo)All demo object is the AppDelegate didFinishLaunchingWithOptions * * * * this method is implemented. If you need that part, just open the comment. [](http://upload-images.jianshu.io/upload_images/1396375-da10e854261fac29.png? imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ! [](http://upload-images.jianshu.io/upload_images/1396375-aeed2b700b2d522f.png? imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ! [](http://upload-images.jianshu.io/upload_images/1396375-aa7520f858807c5b.png? imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) <br># # # #*** SDLunch this round word related use is introduced to this, if you have questions, you can contact SAO Dong to discuss... Thank you. Welcome to SAO Dong SAO Dong will bring you more interesting programming... 😄! [](http://upload-images.jianshu.io/upload_images/1396375-7ecd7fa929b03d97.gif? imageMogr2/auto-orient/strip)Copy the code