|
@@ -7,17 +7,286 @@
|
|
|
|
|
|
#import "WidgetDotView.h"
|
|
|
|
|
|
-@interface WidgetDotView ()
|
|
|
+#define SPOT_WHDTH (24)
|
|
|
|
|
|
+@interface WidgetDotView ()
|
|
|
|
|
|
+@property (nonatomic, assign) KSMetronomeType currentMetronomeType;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation WidgetDotView
|
|
|
+
|
|
|
+
|
|
|
+ (instancetype)shareInstance {
|
|
|
WidgetDotView *view = [[[NSBundle mainBundle] loadNibNamed:@"WidgetDotView" owner:nil options:nil] firstObject];
|
|
|
return view;
|
|
|
}
|
|
|
+
|
|
|
+- (void)createUI {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)updateSpotViewHeightState:(int)currentTotalNo {
|
|
|
+ // 当前圆个数
|
|
|
+ int spotNo;
|
|
|
+
|
|
|
+ if (self.currentMetronomeType == KSMetronomeType1V4) {
|
|
|
+ spotNo = 1;
|
|
|
+ }else if (self.currentMetronomeType == KSMetronomeType2V4){
|
|
|
+ spotNo = 2;
|
|
|
+ }else if (self.currentMetronomeType == KSMetronomeType3V4){
|
|
|
+ spotNo = 3;
|
|
|
+ }else if (self.currentMetronomeType == KSMetronomeType4V4){
|
|
|
+ spotNo = 4;
|
|
|
+ }else{
|
|
|
+ spotNo = 6;
|
|
|
+ }
|
|
|
+
|
|
|
+ UIImageView *currentImageView = [self viewWithTag:currentTotalNo % spotNo +100];
|
|
|
+ currentImageView.highlighted = YES;
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ currentImageView.highlighted = NO;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+- (void)updateSpotView:(KSMetronomeType)metronomeStat {
|
|
|
+
|
|
|
+ self.currentMetronomeType = metronomeStat;
|
|
|
+ [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
|
|
+
|
|
|
+ [self creatSpotImageView:metronomeStat];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)creatSpotImageView:(KSMetronomeType)metronomeStat {
|
|
|
+ if (metronomeStat == KSMetronomeType1V2) {
|
|
|
+ UIImageView *spotView = [self creatSpotImageView];
|
|
|
+ spotView.tag = 100;
|
|
|
+ [self addSubview:spotView];
|
|
|
+ [spotView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.centerX.mas_equalTo(self.mas_centerX);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else if (metronomeStat == KSMetronomeType2V2) {
|
|
|
+ CGFloat xSpace = (KPortraitWidth - SPOT_WHDTH * 2) / 3;
|
|
|
+
|
|
|
+ UIImageView *spotView = [self creatSpotImageView];
|
|
|
+ spotView.tag = 100;
|
|
|
+ [self addSubview:spotView];
|
|
|
+ [spotView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.mas_left).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView1 = [self createWhiteImageView];
|
|
|
+ spotView1.tag = 101;
|
|
|
+ [self addSubview:spotView1];
|
|
|
+ [spotView1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView.mas_right).offset(xSpace);
|
|
|
+ make.centerY.mas_equalTo(0);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else if (metronomeStat == KSMetronomeType1V4) {
|
|
|
+ UIImageView *spotView = [self creatSpotImageView];
|
|
|
+ spotView.tag = 100;
|
|
|
+ [self addSubview:spotView];
|
|
|
+ [spotView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.centerX.mas_equalTo(self.mas_centerX);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else if (metronomeStat == KSMetronomeType2V4) {
|
|
|
+ CGFloat xSpace = (KPortraitWidth - SPOT_WHDTH * 2) / 3;
|
|
|
+
|
|
|
+ UIImageView *spotView = [self creatSpotImageView];
|
|
|
+ spotView.tag = 100;
|
|
|
+ [self addSubview:spotView];
|
|
|
+ [spotView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.mas_left).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView1 = [self createWhiteImageView];
|
|
|
+ spotView1.tag = 101;
|
|
|
+ [self addSubview:spotView1];
|
|
|
+ [spotView1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView.mas_right).offset(xSpace);
|
|
|
+ make.centerY.mas_equalTo(0);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else if (metronomeStat == KSMetronomeType3V4) {
|
|
|
+ CGFloat xSpace = (KPortraitWidth - SPOT_WHDTH * 3) / 4;
|
|
|
+ UIImageView *spotView = [self creatSpotImageView];
|
|
|
+ spotView.tag = 100;
|
|
|
+ [self addSubview:spotView];
|
|
|
+ [spotView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.mas_left).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView1 = [self createWhiteImageView];
|
|
|
+ spotView1.tag = 101;
|
|
|
+ [self addSubview:spotView1];
|
|
|
+ [spotView1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView2 = [self createWhiteImageView];
|
|
|
+ spotView2.tag = 102;
|
|
|
+ [self addSubview:spotView2];
|
|
|
+ [spotView2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView1.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else if (metronomeStat == KSMetronomeType4V4) {
|
|
|
+ CGFloat xSpace = (KPortraitWidth - SPOT_WHDTH * 4) / 5;
|
|
|
+ UIImageView *spotView = [self creatSpotImageView];
|
|
|
+ spotView.tag = 100;
|
|
|
+ [self addSubview:spotView];
|
|
|
+ [spotView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.mas_left).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView1 = [self createWhiteImageView];
|
|
|
+ spotView1.tag = 101;
|
|
|
+ [self addSubview:spotView1];
|
|
|
+ [spotView1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView2 = [self createWhiteImageView];
|
|
|
+ spotView2.tag = 102;
|
|
|
+ [self addSubview:spotView2];
|
|
|
+ [spotView2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView1.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView3 = [self createWhiteImageView];
|
|
|
+ spotView3.tag = 103;
|
|
|
+ [self addSubview:spotView3];
|
|
|
+ [spotView3 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView2.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else if (metronomeStat == KSMetronomeType3V8) {
|
|
|
+ CGFloat xSpace = (KPortraitWidth - SPOT_WHDTH * 3) / 4;
|
|
|
+ UIImageView *spotView = [self creatSpotImageView];
|
|
|
+ spotView.tag = 100;
|
|
|
+ [self addSubview:spotView];
|
|
|
+ [spotView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.mas_left).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView1 = [self createWhiteImageView];
|
|
|
+ spotView1.tag = 101;
|
|
|
+ [self addSubview:spotView1];
|
|
|
+ [spotView1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView2 = [self createWhiteImageView];
|
|
|
+ spotView2.tag = 102;
|
|
|
+ [self addSubview:spotView2];
|
|
|
+ [spotView2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView1.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ else if (metronomeStat == KSMetronomeType6V8) {
|
|
|
+ CGFloat xSpace = (KPortraitWidth - SPOT_WHDTH * 6) / 7;
|
|
|
+ UIImageView *spotView = [self creatSpotImageView];
|
|
|
+ spotView.tag = 100;
|
|
|
+ [self addSubview:spotView];
|
|
|
+ [spotView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.mas_left).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView1 = [self createWhiteImageView];
|
|
|
+ spotView1.tag = 101;
|
|
|
+ [self addSubview:spotView1];
|
|
|
+ [spotView1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView2 = [self createWhiteImageView];
|
|
|
+ spotView2.tag = 102;
|
|
|
+ [self addSubview:spotView2];
|
|
|
+ [spotView2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView1.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView3 = [self createWhiteImageView];
|
|
|
+ spotView3.tag = 103;
|
|
|
+ [self addSubview:spotView3];
|
|
|
+ [spotView3 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView2.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView4 = [self createWhiteImageView];
|
|
|
+ spotView4.tag = 104;
|
|
|
+ [self addSubview:spotView4];
|
|
|
+ [spotView4 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView3.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *spotView5 = [self createWhiteImageView];
|
|
|
+ spotView5.tag = 105;
|
|
|
+ [self addSubview:spotView5];
|
|
|
+ [spotView5 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(spotView4.mas_right).offset(xSpace);
|
|
|
+ make.bottom.mas_equalTo(self.mas_bottom).offset(-12);
|
|
|
+ make.width.height.mas_equalTo(SPOT_WHDTH);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark -- 创建大圆View
|
|
|
+- (UIImageView *)creatSpotImageView{
|
|
|
+
|
|
|
+ UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"metro_whiteSpot"] highlightedImage:[UIImage imageNamed:@"metro_hightSpot"]];
|
|
|
+ return imageView;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIImageView *)createWhiteImageView {
|
|
|
+ UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"metro_whiteSpot"] highlightedImage:[UIImage imageNamed:@"metro_hightSpot"]];
|
|
|
+ return imageView;
|
|
|
+}
|
|
|
/*
|
|
|
// Only override drawRect: if you perform custom drawing.
|
|
|
// An empty implementation adversely affects performance during animation.
|