iOS Development-Custom Matte view (boot, function description) source + parsing

Source: Internet
Author: User

iOS Development-Custom Matte view (boot, function description) source + parsing

We usually use the app, often in the first use, there will be similar to "novice tutorial" and other things, to guide how we should use the app.

But this "novice tutorial" is different from the regular boot page (the introductory page is the kind of introduction view that pops up when you first open the app.) He is static, does not need to interact with the user, can directly page over, or skip directly. The so-called "novice Tutorial", is to follow the app prompts, step by step followed by the completion.

What is the benefit of this "beginner's tutorial"?

    1. Instruct the user about the operation. For example, how to adjust the volume, how to set the focal length ...
    2. Restrict the user from populating the necessary information to complete the necessary actions.

Now everyone should know what this is all about. In order to achieve such a function, it is generally used masking layer effect, today took a little time to encapsulate such a function. At the same time to share the source to my GitHub, you need to download.

Download Link: Ylzholedview

At the same time, also wrote a demo, the effect is as follows:

I encapsulated this file (Ylzholedview), the main implementation of the following functions:
1. Add multiple style spotlight effects. (round, rectangle, rounded rectangle, custom view)
2. Click the area to support the delegate callback
3. Control events in the UIView are penetrated. (The button in the demo is below the mask layer, but responds correctly to the Click event, which is the event penetration)

Well, the general introduction is here, the following is a brief explanation of the core code:

Delegate callback

YLZHoledView.h

@class YLZHoledView;@protocol YLZHoledViewDelegate <NSObject>- (void)holedView:(YLZHoledView *)holedView didSelectHoleAtIndex:(NSUInteger)index;@end

YLZHoledView.m

 #pragma mark-tap Gesture     -(void ) Tapgesturedetectedforgesture: (UITapGestureRecognizer *) gesture { if  ([self  .holeviewdelegate  respondstoselector :  @selector  (holedview:didselectholeatindex:)]) {         Cgpoint  touchlocation = [gesture Locationinview:self ]; [self  .holeviewdelegate  Holedview:self  didselectholeatindex:[self      Holeviewindexforatpoint:touchlocation]]; } }

This first adds a gesture to the custom view and then
- (NSUInteger)holeViewIndexForAtPoint:(CGPoint)touchLocationDetermines whether the click Range belongs to the view added in the matte layer and then sends the delegate.

Then in our implementation class, that is, the implementation of this delegate, you can use index to do related operations. My demo is just a simple print.

Spotlight Effect

I've encapsulated several common types here. (round, rectangle, rounded rectangle, custom view)

typedef NS_ENUM(NSInteger, YLZHoleType) {     YLZHoleTypeCirle,     YLZHoleTypeRect,     YLZHoleTypeRoundedRect,     YLZHoleTypeCustomRect };

and then rewrite
- (void)drawRect:(CGRect)rect
Override the corresponding effect by typing the judgment.

For example, a circular code:

if (hole. Holetype= = Ylzholetyperoundedrect) {ylzroundedrecthole *recthole = (Ylzroundedrecthole *) hole;CGRect holerectintersection = cgrectintersection (recthole. Holerect, self. Frame);Uibezierpath *bezierpath = [Uibezierpath bezierpathwithroundedrect:holerectintersection Cornerradius:recthole. Holecornerradius];Cgcontextsetfillcolorwithcolor (Uigraphicsgetcurrentcontext (), [[Uicolor Clearcolor] cgcolor]);Cgcontextaddpath (Uigraphicsgetcurrentcontext (), Bezierpath. Cgpath);Cgcontextsetblendmode (Uigraphicsgetcurrentcontext (), kcgblendmodeclear);Cgcontextfillpath (Uigraphicsgetcurrentcontext ());}
Event penetration

Before that, mention a method.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
Recursively calls-pointinside:withevent:. Point was in the receiver ' s coordinate system

As long as the top-level UIView HitTest method is implemented, in some cases, a button instance is returned to the lower layer, which is equivalent to revealing the button's event, such as when a click Falls on the button, regardless of how many layers of the button in the UIView can be dug out.

So, rewrite the HitTest method.

  #pragma mark-uiview Overrides -(uiview  *) HitTest: (cgpoint ) point withevent: (Uievent *) event {uiview  *hitview = [super  hittest:point withevent:event]; if      (Hitview = = self ) {for  (uiview  *focus in self  .focusview " {if  (CGRect Containspoint (Focus.frame , point)) {return  Focus; }}} return  Hitview; }

iOS Development-Custom Matte view (boot, function description) source + parsing

Related Article

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.