Last active
December 17, 2015 20:29
-
-
Save monjer/5667606 to your computer and use it in GitHub Desktop.
UIView一些简单工具方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIView+Util.h | |
| // | |
| // Created by manjun.han on 12-12-5. | |
| // Copyright (c) 2012年 All rights reserved. | |
| // | |
| #import <UIKit/UIKit.h> | |
| @interface UIView (Util) | |
| -(UIView*)subViewContainTouchPoint:(CGPoint)touchPoint ; | |
| - (void)removeAllSubviews ; | |
| - (void)removeAllSublayers ; | |
| - (void)removeAllGestures ; | |
| - (void)removeGestureByType:(Class)gestureTypeClass ; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIView+Util.m | |
| // | |
| // Created by manjun.han on 12-12-5. | |
| // Copyright (c) 2012年 All rights reserved. | |
| // | |
| #import "UIView+Util.h" | |
| #import <QuartzCore/QuartzCore.h> | |
| @implementation UIView (Util) | |
| - (UIView*)subViewContainTouchPoint:(CGPoint)touchPoint ; | |
| { | |
| if(!self.subviews || self.subviews.count == 0){ | |
| return nil ; | |
| } | |
| UIView *subView ; | |
| for(int i = self.subviews.count-1 ; i >= 0 ; i--){ | |
| subView = [self.subviews objectAtIndex:i]; | |
| if(CGRectContainsPoint(subView.frame, touchPoint)){ | |
| return subView ; | |
| } | |
| } | |
| return nil ; | |
| } | |
| - (void)removeAllSubviews | |
| { | |
| for (UIView *subview in self.subviews) { | |
| [subview removeFromSuperview] ; | |
| } | |
| } | |
| - (void)removeAllSublayers | |
| { | |
| CALayer *layer = self.layer ; | |
| for (CALayer *sublayer in layer.sublayers) { | |
| [sublayer removeFromSuperlayer] ; | |
| } | |
| } | |
| - (void)removeAllGestures | |
| { | |
| for (UIGestureRecognizer *gesture in self.gestureRecognizers) { | |
| [self removeGestureRecognizer:gesture] ; | |
| } | |
| } | |
| - (void)removeGestureByType:(Class)gestureTypeClass | |
| { | |
| for (UIGestureRecognizer *gesture in self.gestureRecognizers) { | |
| if ([gesture isKindOfClass:gestureTypeClass]) { | |
| [self removeGestureRecognizer:gesture]; | |
| } | |
| } | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment