123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- //
- // UIView+LBExtension.m
- // XianYu
- //
- // Created by li bo on 16/5/28.
- // Copyright © 2016年 li bo. All rights reserved.
- //
- #import "UIView+JZExtension.h"
- @implementation UIView (JZExtension)
- - (void)setX:(CGFloat)x
- {
- CGRect frame = self.frame;
- frame.origin.x = x;
- self.frame = frame;
- }
- - (CGFloat)x
- {
- return self.frame.origin.x;
- }
- - (void)setY:(CGFloat)y
- {
- CGRect frame = self.frame;
- frame.origin.y = y;
- self.frame = frame;
- }
- - (CGFloat)y
- {
- return self.frame.origin.y;
- }
- - (void)setWidth:(CGFloat)width
- {
- CGRect frame = self.frame;
- frame.size.width = width;
- self.frame = frame;
- }
- - (CGFloat)width
- {
- return self.frame.size.width;
- }
- - (void)setHeight:(CGFloat)height
- {
- CGRect frame = self.frame;
- frame.size.height = height;
- self.frame= frame;
- }
- - (CGFloat)height
- {
- return self.frame.size.height;
- }
- - (void)setSize:(CGSize)size
- {
- CGRect frame = self.frame;
- frame.size = size;
- self.frame = frame;
- }
- - (CGFloat)right{
- return CGRectGetMaxX(self.frame);
- }
- - (CGFloat)bottom{
- return CGRectGetMaxY(self.frame);
- }
- - (CGSize)size
- {
- return self.frame.size;
- }
- - (void)setCenterX:(CGFloat)centerX
- {
- CGPoint center = self.center;
- center.x = centerX;
- self.center = center;
- }
- - (CGFloat)centerX
- {
- return self.center.x;
- }
- - (void)setCenterY:(CGFloat)centerY
- {
- CGPoint center = self.center;
- center.y = centerY;
- self.center = center;
- }
- - (CGFloat)centerY
- {
- return self.center.y;
- }
- - (void)alignHorizontal
- {
- self.x = (self.superview.width - self.width) * 0.5;
- }
- - (void)alignVertical
- {
- self.y = (self.superview.height - self.height) *0.5;
- }
- - (void)setBorderWidth:(CGFloat)borderWidth
- {
-
- if (borderWidth < 0) {
- return;
- }
- self.layer.borderWidth = borderWidth;
- }
- - (void)setBorderColor:(UIColor *)borderColor
- {
- self.layer.borderColor = borderColor.CGColor;
- }
- - (void)setCornerRadius:(CGFloat)cornerRadius
- {
- self.layer.cornerRadius = cornerRadius;
- self.layer.masksToBounds = YES;
- }
- - (BOOL)isShowOnWindow
- {
- //主窗口
- UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
- //相对于父控件转换之后的rect
- CGRect newRect = [keyWindow convertRect:self.frame fromView:self.superview];
- //主窗口的bounds
- CGRect winBounds = keyWindow.bounds;
- //判断两个坐标系是否有交汇的地方,返回bool值
- BOOL isIntersects = CGRectIntersectsRect(newRect, winBounds);
- if (self.hidden != YES && self.alpha >0.01 && self.window == keyWindow && isIntersects) {
- return YES;
- }else{
- return NO;
- }
- }
- - (CGFloat)borderWidth
- {
- return self.borderWidth;
- }
- - (UIColor *)borderColor
- {
- return self.borderColor;
- }
- - (CGFloat)cornerRadius
- {
- return self.cornerRadius;
- }
- - (UIViewController *)parentController
- {
- UIResponder *responder = [self nextResponder];
- while (responder) {
- if ([responder isKindOfClass:[UIViewController class]]) {
- return (UIViewController *)responder;
- }
- responder = [responder nextResponder];
- }
- return nil;
- }
- - (void)addLeftCornersWithcornerRadii:(CGSize )size{
- UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:size];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = self.bounds;
- maskLayer.path = maskPath.CGPath;
- self.layer.mask = maskLayer;
- }
- - (void)addCornerRadiusByRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii{
- UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:cornerRadii];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = self.bounds;
- maskLayer.path = maskPath.CGPath;
- self.layer.mask = maskLayer;
- }
- - (void)addKeyAnimation{
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
- animation.duration = 0.30;
- animation.removedOnCompletion = YES;
- animation.fillMode = kCAFillModeForwards;
- NSMutableArray *values = [NSMutableArray array];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.0)]];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
- animation.values = values;
- [self.layer addAnimation:animation forKey:nil];
- }
- @end
|