//
//  UIView+GMExtension.m
//  Gengmei
//
//  Created by Q14 on 2018/9/28.
//  Copyright © 2018年 更美互动信息科技有限公司. All rights reserved.
//

#import "UIView+GMExtension.h"
//#import "GMAlbumListViewController.h"
//#import "GMPhotoTools.h"
@import GMKit;
@implementation UIView (GMExtension)

- (void)setGm_x:(CGFloat)gm_x
{
    CGRect frame = self.frame;
    frame.origin.x = gm_x;
    self.frame = frame;
}

- (CGFloat)gm_x
{
    return self.frame.origin.x;
}

- (void)setGm_y:(CGFloat)gm_y
{
    CGRect frame = self.frame;
    frame.origin.y = gm_y;
    self.frame = frame;
}

- (CGFloat)gm_y
{
    return self.frame.origin.y;
}

- (void)setGm_w:(CGFloat)gm_w
{
    CGRect frame = self.frame;
    frame.size.width = gm_w;
    self.frame = frame;
}

- (CGFloat)gm_w
{
    return self.frame.size.width;
}

- (void)setGm_h:(CGFloat)gm_h
{
    CGRect frame = self.frame;
    frame.size.height = gm_h;
    self.frame = frame;
}

- (CGFloat)gm_h
{
    return self.frame.size.height;
}

- (void)setGm_size:(CGSize)gm_size
{
    CGRect frame = self.frame;
    frame.size = gm_size;
    self.frame = frame;
}

- (CGSize)gm_size
{
    return self.frame.size;
}

- (void)setGm_origin:(CGPoint)gm_origin
{
    CGRect frame = self.frame;
    frame.origin = gm_origin;
    self.frame = frame;
}

- (CGPoint)gm_origin
{
    return self.frame.origin;
}

/**
 获取当前视图的控制器
 
 @return 控制器
 */
- (UIViewController*)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UINavigationController class]] || [nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}

- (void)handleLoading {
    [UIView cancelPreviousPerformRequestsWithTarget:self];
    for (UIView *view in self.subviews) {
        if (view.tag == 10086) {
            [UIView animateWithDuration:0.2f animations:^{
                view.alpha = 0;
            } completion:^(BOOL finished) {
                [view removeFromSuperview];
            }];
        }
    }
}

- (void)handleGraceTimer {
    [UIView cancelPreviousPerformRequestsWithTarget:self];
    for (UIView *view in self.subviews) {
        if (view.tag == 1008611) {
            [UIView animateWithDuration:0.2f animations:^{
                view.alpha = 0;
            } completion:^(BOOL finished) {
                [view removeFromSuperview];
            }];
        }
    }
}

@end
