-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathMartFunctionTipView.m
110 lines (100 loc) · 3.23 KB
/
MartFunctionTipView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// MartFunctionTipView.m
// CodingMart
//
// Created by Ease on 16/8/12.
// Copyright © 2016年 net.coding. All rights reserved.
//
#import "MartFunctionTipView.h"
#import <BlocksKit/BlocksKit+UIKit.h>
@interface MartFunctionTipView ()
@property (strong, nonatomic) UIImageView *imageV;
@property (strong, nonatomic) NSArray *imageNames;
@property (assign, nonatomic) NSUInteger curIndex;
@end
@implementation MartFunctionTipView
- (instancetype)init
{
self = [super init];
if (self) {
_imageV = [UIImageView new];
_imageV.frame = self.frame = kScreen_Bounds;
_imageV.backgroundColor = self.backgroundColor = [UIColor clearColor];
[self addSubview:_imageV];
__weak typeof(self) weakSelf = self;;
_imageV.userInteractionEnabled = YES;
[_imageV bk_whenTapped:^{
[weakSelf tapped];
}];
}
return self;
}
- (void)tapped{
_curIndex += 1;
if (_imageNames.count > _curIndex) {
_imageV.image = [UIImage imageNamed:_imageNames[_curIndex]];
}else{
[self dismiss];
}
}
+ (void)showFunctionImages:(NSArray *)imageNames{
if (kScreen_Height == 480) {//iPhone 4 的尺寸,忽略
return;
}
if (imageNames.count <= 0) {
return;
}
MartFunctionTipView *tipV = [MartFunctionTipView new];
tipV.imageNames = imageNames;
[tipV show];
}
+ (void)showFunctionImages:(NSArray *)imageNames onlyOneTime:(BOOL)onlyOneTime{
if (kScreen_Height == 480) {//iPhone 4 的尺寸,忽略
return;
}
if (imageNames.count <= 0) {
return;
}
if (onlyOneTime) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *hasShowedImages = @[].mutableCopy;
for (NSString *imageName in imageNames) {
if ([defaults objectForKey:imageName]) {
[hasShowedImages addObject:imageName];
}else{
[defaults setObject:@1 forKey:imageName];
}
}
[defaults synchronize];
NSMutableArray *needShowImages = imageNames.mutableCopy;
[needShowImages removeObjectsInArray:hasShowedImages];
imageNames = needShowImages;
}
[self showFunctionImages:imageNames];
}
- (void)show{
if (_imageNames.count <= 0) {
return;
}
_curIndex = 0;
_imageV.image = [UIImage imageNamed:_imageNames[_curIndex]];
[kKeyWindow addSubview:self];
}
- (void)dismiss{
[self removeFromSuperview];
}
+ (AMPopTip *)showText:(NSString *)text direction:(AMPopTipDirection)direction bubbleOffset:(CGFloat)bubbleOffset inView:(UIView *)view fromFrame:(CGRect)frame dismissHandler:(void (^)())dismissHandler{
AMPopTip *popTip = [AMPopTip popTip];
popTip.shouldDismissOnTap = YES;
popTip.font = [UIFont systemFontOfSize:15];
popTip.radius = 4.0;
popTip.arrowSize = CGSizeMake(10, 5);
popTip.padding = 10;
popTip.dismissHandler = dismissHandler;
// popTip.popoverColor = [UIColor colorWithHexString:@"0x262728" andAlpha:0.8];
popTip.popoverColor = kColorBrandBlue;
popTip.bubbleOffset = bubbleOffset;
[popTip showText:text direction:direction maxWidth:kScreen_Width - 30 inView:view fromFrame:frame duration:0];
return popTip;
}
@end