Files
yinmeng-ios/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGraffitiGiftView.m
2022-08-22 20:07:36 +08:00

308 lines
9.1 KiB
Objective-C

//
// XPGraffitiGiftView.m
// xplan-ios
//
// Created by 冯硕 on 2022/8/22.
//
#import "XPGraffitiGiftView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "XPMacro.h"
@interface XPGraffitiGiftView ()
///回话的内容
@property (nonatomic,strong) UIView * contentView;
///类型
@property (nonatomic,strong) UIStackView *tipsStackView;
///✋🏻
@property (nonatomic,strong) UIImageView *handImageView;
///提醒
@property (nonatomic,strong) UILabel *tipsLabel;
///toolView
@property (nonatomic,strong) UIView * toolView;
///至少花多少个
@property (nonatomic,strong) UILabel *titleLabel;
///类型
@property (nonatomic,strong) UIStackView *toolStackView;
///切换
@property (nonatomic,strong) UIButton *changeButton;
///撤销
@property (nonatomic,strong) UIButton *repealButton;
///删除
@property (nonatomic,strong) UIButton *deleteButton;
///关闭
@property (nonatomic,strong) UIButton *closeButton;
@property (nonatomic,assign) CGPoint panPoint;
///
@property (nonatomic,assign) CGPoint beginPoint;
///
@property (nonatomic,assign) CGFloat step;
///
@property (nonatomic,strong) NSMutableArray *datasource;
///
@property (nonatomic,assign) int index;
@end
@implementation XPGraffitiGiftView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.step = 20;
UIPanGestureRecognizer * panGes = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
[self addGestureRecognizer:panGes];
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.contentView];
[self.contentView addSubview:self.tipsStackView];
[self.contentView addSubview:self.toolView];
[self.tipsStackView addArrangedSubview:self.handImageView];
[self.tipsStackView addArrangedSubview:self.tipsLabel];
[self.toolView addSubview:self.titleLabel];
[self.toolView addSubview:self.toolStackView];
[self.toolStackView addArrangedSubview:self.changeButton];
[self.toolStackView addArrangedSubview:self.repealButton];
[self.toolStackView addArrangedSubview:self.deleteButton];
[self.toolStackView addArrangedSubview:self.closeButton];
}
- (void)initSubViewConstraints {
CGFloat avatarHeight = (43 + 15 * 2);
CGFloat bottomHeight = (45);
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(KScreenHeight - avatarHeight - bottomHeight);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
[self.tipsStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.contentView);
make.width.mas_equalTo(KScreenWidth);
}];
[self.handImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(78, 93));
}];
[self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.left.right.mas_equalTo(self.contentView);
make.height.mas_equalTo(56);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.toolView).offset(15);
make.centerY.mas_equalTo(self.toolView);
}];
[self.toolStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.toolView).offset(-15);
make.height.mas_equalTo(22);
make.centerY.mas_equalTo(self.toolView);
}];
[self.changeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(50);
}];
[self.repealButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(22);
}];
[self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(22);
}];
[self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(22);
}];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
self.tipsStackView.hidden = YES;
UITouch *touch = touches.anyObject;
CGPoint point = [touch locationInView:self.contentView];
self.beginPoint = point;
NSLog(@"beginPoint:X:%.2f, Y:%.2f", point.x, point.y);
}
- (void)panAction:(UIPanGestureRecognizer *)tap {
CGPoint point = [tap translationInView:self.contentView];
NSLog(@"panAction:X:%.2f, Y:%.2f", point.x, point.y);
CGFloat dx = [self myAbs:point.x - self.panPoint.x];
CGFloat dy = [self myAbs:point.y - self.panPoint.y];
CGPoint drawPoint = CGPointMake(self.beginPoint.x + point.x , self.beginPoint.y + point.y);
if ((dx * dx + dy * dy) > 2 * self.step * self.step) {
[self addSubView:drawPoint];
self.panPoint = point;
}
}
- (int)myAbs:(int)num {
if (num >= 0) {
return num;
}
return -num;
}
- (void)addSubView:(CGPoint)point {
UIImageView * imageView = [[UIImageView alloc] init];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.layer.masksToBounds = YES;
imageView.image = self.image;
imageView.frame = CGRectMake(point.x, point.y, 20, 20);
[self.contentView addSubview:imageView];
}
#pragma mark - Event Response
- (void)changeButtonAction:(UIButton *)sender {
}
- (void)repealButtonAction:(UIButton *)sender {
}
- (void)deleteButtonAction:(UIButton *)sender {
}
- (void)closeButtonAction:(UIButton *)sender {
}
#pragma mark - Getters And Setters
- (UIView *)contentView {
if (!_contentView) {
_contentView = [[UIView alloc] init];
_contentView.backgroundColor = UIColorRGBAlpha(0x000000, 0.7);
}
return _contentView;
}
- (UIStackView *)tipsStackView {
if (!_tipsStackView) {
_tipsStackView = [[UIStackView alloc] init];
_tipsStackView.axis = UILayoutConstraintAxisVertical;
_tipsStackView.distribution = UIStackViewDistributionFill;
_tipsStackView.alignment = UIStackViewAlignmentCenter;
_tipsStackView.spacing = 17;
}
return _tipsStackView;
}
- (UIImageView *)handImageView {
if (!_handImageView) {
_handImageView = [[UIImageView alloc] init];
_handImageView.userInteractionEnabled = YES;
_handImageView.image = [UIImage imageNamed:@"room_gift_graffiti_hand"];
}
return _handImageView;
}
- (UILabel *)tipsLabel {
if (!_tipsLabel) {
_tipsLabel = [[UILabel alloc] init];
_tipsLabel.font = [UIFont systemFontOfSize:14];
_tipsLabel.textColor = [ThemeColor textThirdColor];
_tipsLabel.text = @"滑动手指,绘制图形";
}
return _tipsLabel;
}
- (UIView *)toolView {
if (!_toolView) {
_toolView = [[UIView alloc] init];
_toolView.backgroundColor = UIColorRGBAlpha(0xFFFFFF, 0.2);
CAShapeLayer * layer = [CAShapeLayer layer];
layer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, KScreenWidth, 56) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)].CGPath;
_toolView.layer.mask = layer;
}
return _toolView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:14];
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.text = @"至少画10个才能送出";
}
return _titleLabel;
}
- (UIStackView *)toolStackView {
if (!_toolStackView) {
_toolStackView = [[UIStackView alloc] init];
_toolStackView.axis = UILayoutConstraintAxisHorizontal;
_toolStackView.distribution = UIStackViewDistributionFill;
_toolStackView.alignment = UIStackViewAlignmentCenter;
_toolStackView.spacing = 12;
}
return _toolStackView;
}
- (UIButton *)changeButton {
if (!_changeButton) {
_changeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_changeButton setTitle:@"切换涂鸦" forState:UIControlStateNormal];
[_changeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_changeButton.titleLabel.font = [UIFont systemFontOfSize:12];
[_changeButton addTarget:self action:@selector(changeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _changeButton;
}
- (UIButton *)repealButton {
if (!_repealButton) {
_repealButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_repealButton setImage:[UIImage imageNamed:@"room_gift_graffiti_repeal"] forState:UIControlStateNormal];
[_repealButton setImage:[UIImage imageNamed:@"room_gift_graffiti_repeal"] forState:UIControlStateSelected];
[_repealButton addTarget:self action:@selector(repealButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _repealButton;
}
- (UIButton *)deleteButton {
if (!_deleteButton) {
_deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_deleteButton setImage:[UIImage imageNamed:@"room_gift_graffiti_delete"] forState:UIControlStateNormal];
[_deleteButton setImage:[UIImage imageNamed:@"room_gift_graffiti_delete"] forState:UIControlStateSelected];
[_deleteButton addTarget:self action:@selector(deleteButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _deleteButton;
}
- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeButton setImage:[UIImage imageNamed:@"room_gift_graffiti_close"] forState:UIControlStateNormal];
[_closeButton setImage:[UIImage imageNamed:@"room_gift_graffiti_close"] forState:UIControlStateSelected];
[_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
@end