iOS Transparent boot page

Source: Internet
Author: User

First, the effect shows

Write a picture description here
This type of novice boot is more common, to tell the user what a button does, or to alert the user to some kind of interaction. The boot style is to add a translucent guide to the interface, highlighting the area to be highlighted

Second, how to do?
There are a variety of scenarios, different scenarios have different pros and cons, here are two common scenarios listed

    1. Scenario One: Generating an entire guide map
      (1). Export the Guide diagram
      Let the designer export each size of the guide map, the guide map contains only the Guide section, excluding the background, the exported guide map style is as follows:

Write a picture description here
Need to export Iphone4,iphone5,iphone6,iphone6 plus a total of 4 sizes, if the ipad, also need to export the ipad

(2). Encoding
Because the whole diagram is exported, the code part is simple, no need to consider the layout problem, directly generate a imageview put up, and then add a click event to it

The code is as follows:

    • (void) Addguideview {
      NSString *imagename = nil;
      if (device_is_iphone5) {
      ImageName = @ "guide-568h";
      } else {
      ImageName = @ "Guide";
      }

      UIImage image = [UIImage imagenamed:imagename];
      Uiimageview
      ImageView = [[Uiimageview alloc] initwithimage:image];
      Imageview.frame = Self.view.bounds;
      imageview.userinteractionenabled = YES;

      UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Dismissguideview) ];
      [ImageView Addgesturerecognizer:tap];

      [Self.view Addsubview:imageview];
      }
      Special attention is needed here:
      @3x pictures need to iOS8 above the system can be automatically recognized, if you want to forward compatibility, the picture name there need to determine the device type, and then specify the corresponding picture name

(3). Advantages and Disadvantages
The advantage of this scheme is that

A. Fast
As long as the designers do a good job, the layer will be exported to a variety of specifications, 90% of the work of the designers, programmers simply need to add views and events can easily

B. Low maintenance costs
When the interface changes, or the guide diagram needs to be adjusted, only the designer needs to regenerate the image, and then replace it.

But there are many drawbacks to this approach:

A. The picture occupies a large space
Each device a picture, picture or full-screen specifications, may also be suitable for horizontal screen, obviously will increase the size of the app installation package

B. Images cannot be reused
A guide map can only be used in one place, and other places are not likely to be used.

    1. Scenario Two: Picture stitching
      Picture stitching is like this, through a number of pictures into a mask layer, and then put other elements, as shown in

Write a picture description here
(1). Prepare picture
Here are 3 pictures to prepare

A. Hollow Oval mask Layer

Write a picture description here
The middle is transparent, the surrounding is white, the white part can be changed to any color in the mask process

B. Small arrow

Write a picture description here

C. OK button

Write a picture description here
(2). Encoding
This section describes the process of writing part of the code

A. Interface
Definition of the interface:

(void) Showinview: (UIView) View maskbtn: (UIButton) btn;
View: Parent view of the guide diagram
BTN: Masked button
Implementation of the interface:

(void) Showinview: (UIView) View maskbtn: (UIButton) btn {
Self.parentview = view;
SELF.MASKBTN = BTN;

Self.alpha = 0;
[View Addsubview:self];
[UIView animatewithduration:0.2 animations:^{

Self.alpha = 1;
} Completion:nil];
}

B. Modifying the Mask layer
After loading the hollow oval image, first process the white area and change it to black translucent
UIImage image = [UIImage imagenamed:@ "Whitemask"];
image = [Image Maskimage:[[uicolor Blackcolor] colorwithalphacomponent:0.71];
Uiimageview ImageView = [[Uiimageview alloc] initwithimage:image];

(UIImage) Maskimage: (Uicolor) MaskColor
{
CGRect rect = CGRectMake (0, 0, self.size.width, self.size.height);

Uigraphicsbeginimagecontext (rect.size);

Cgcontextref context = Uigraphicsgetcurrentcontext ();
CGCONTEXTTRANSLATECTM (context, 0, rect.size.height);
CGCONTEXTSCALECTM (Context, 1.0,-1.0);
Cgcontextcliptomask (context, rect, self.) Cgimage);
Cgcontextsetfillcolorwithcolor (context, maskcolor.cgcolor);
Cgcontextfillrect (context, rect);

UIImage *smallimage = Uigraphicsgetimagefromcurrentimagecontext ();

Uigraphicsendimagecontext ();

return smallimage;
}
This will change the white part of the image to any color, and we'll turn the hollow oval image into this

Write a picture description here

C. Generate up and down 4 black translucent views
Placed in the upper, lower, left, and right four positions of the hollow ellipse image respectively

(UIView *) Topmaskview {
if (!_topmaskview) {

UIView *view = [[UIView alloc] init];
View.backgroundcolor = [[Uicolor blackcolor] colorwithalphacomponent:0.71];
Topmaskview = view;
}
return
Topmaskview;
}

(UIView *) Bottommaskview {
if (!_bottommaskview) {

UIView *view = [[UIView alloc] init];
View.backgroundcolor = [[Uicolor blackcolor] colorwithalphacomponent:0.71];
Bottommaskview = view;
}
return
Bottommaskview;
}

(UIView *) Leftmaskview {
if (!_leftmaskview) {

UIView *view = [[UIView alloc] init];
View.backgroundcolor = [[Uicolor blackcolor] colorwithalphacomponent:0.71];
Leftmaskview = view;
}
return
Leftmaskview;
}

(UIView *) Rightmaskview {
if (!_rightmaskview) {

UIView *view = [[UIView alloc] init];
View.backgroundcolor = [[Uicolor blackcolor] colorwithalphacomponent:0.71];
Rightmaskview = view;
}
return
Rightmaskview;
}

D. View layout
Here are a few points to keep in mind:
C-1. The value of the x,y,width,height of the tiled view needs to be rounded up, because the floating-point number may cause white edges in the articulation area, especially on the IPhone6 Plus, because of the resolution of the phone, so it's best to use integers

C-2. Layout in the Layoutsubviews function, where the benefits of layout are smooth transitions across the screen, and do not need to be updated manually

The layout code is as follows:

(void) Layoutsubviews {
[Super Layoutsubviews];
Self.frame = parentview.bounds;
Maskbg.frame = Self.bounds;
_btnmaskview.center = [maskbtn.superview convertpoint:maskbtn.center Toview:_maskbtn.superview];

CGRect btnmaskrect = btnmaskview.frame;
Btnmaskrect.size = Cgsizemake (Floor (btnMaskRect.size.width), Floor (btnMaskRect.size.height));
Btnmaskrect.origin = Cgpointmake (Floor (btnmaskrect.origin.x), Floor (BTNMASKRECT.ORIGIN.Y));
Btnmaskview.frame = Btnmaskrect;

Topmaskview.left = 0;
topmaskview.top = 0;
topmaskview.height = btnmaskview.top;
_topmaskview.width = Self.width;

Bottommaskview.left = 0;
Bottommaskview.top = Btnmaskview.bottom;
Bottommaskview.width = Self.width;
bottommaskview.height = self.height- bottommaskview.top;

Leftmaskview.left = 0;
Leftmaskview.top = btnmaskview.top;
Leftmaskview.width = Btnmaskview.left;
Leftmaskview.height = _btnmaskview.height;

rightmaskview.left = btnmaskview.right;
rightmaskview.top = btnmaskview.top;
rightmaskview.width = self.width- rightmaskview.left;
rightmaskview.height = btnmaskview.height;

arrwoview.right = Btnmaskview.left + 24;
arrwoview.bottom = btnmaskview.top-8;
tipslabel.right = arrwoview.left-6;
Tipslabel.bottom = arrwoview.top + 10;

Okbtn.centerx = SELF.WIDTH/2;
Okbtn.bottom = _btnmaskview.top-80;
}

(3). Advantages and Disadvantages
Advantages:

A. Space saving
Usually you just need a few small plots, and then you can assemble them into a guide diagram.

B. Images can be reused
Pictures of buttons, ellipses, and small arrows may be used by other guides

Disadvantages:

A. Longer encoding time
Each interface element needs to be coded to implement, and each change also needs to adjust the code

Iii. Summary
The first scheme is more suitable for small projects, mainly speed, suitable for fast iteration
The second option is suitable for long-term renewal projects, saving app space

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

iOS Transparent boot page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.