提交
This commit is contained in:
@@ -536,74 +536,98 @@ static NSInteger toSlowCount = 4;
|
||||
dispatch_source_set_event_handler(_fastTimer, ^{
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
if (!strongSelf) return;
|
||||
|
||||
// 将需要的数据提前捕获到局部变量中
|
||||
__block NSInteger roundCount = strongSelf.roundCount;
|
||||
__block NSInteger currentIndex = strongSelf.currentIndex;
|
||||
NSArray *finishTargetArrayIndex = [strongSelf.finishTargetArrayIndex copy];
|
||||
NSMutableArray *targetArrayIndex = [strongSelf.targetArrayIndex mutableCopy];
|
||||
__block QXSkyDrawBtnType startType = strongSelf.startType;
|
||||
|
||||
// 如果需要更新UI,切换到主线程
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
strongSelf.roundCount++;
|
||||
if ((strongSelf.roundCount / giftMaxCount == minRoundCount) && strongSelf.startType != QXSkyDrawBtnTypeOne) {
|
||||
// 再次检查 strongSelf 是否存在
|
||||
__strong typeof(weakSelf) strongSelfInMain = weakSelf;
|
||||
if (!strongSelfInMain) return;
|
||||
|
||||
// 使用局部变量进行计算,避免频繁访问属性
|
||||
roundCount++;
|
||||
NSInteger newCurrentIndex = roundCount % giftMaxCount;
|
||||
|
||||
if ((roundCount / giftMaxCount == minRoundCount) && startType != QXSkyDrawBtnTypeOne) {
|
||||
BOOL has = NO;
|
||||
for (NSNumber *index in self.finishTargetArrayIndex) {
|
||||
if (index.integerValue == self.currentIndex) {
|
||||
for (NSNumber *index in finishTargetArrayIndex) {
|
||||
if (index.integerValue == currentIndex) {
|
||||
has = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.currentGiftView.isSelected = NO;
|
||||
|
||||
strongSelfInMain.currentGiftView.isSelected = NO;
|
||||
|
||||
QXSkyPraizeSubView *giftView = strongSelfInMain.allViewsArray[newCurrentIndex];
|
||||
if (has) {
|
||||
QXSkyPraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
||||
giftView.isSelected = YES;
|
||||
}else{
|
||||
QXSkyPraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
||||
} else {
|
||||
giftView.isSelected = NO;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
/// 把上一个选中状态置为未选中
|
||||
strongSelf.currentGiftView.isSelected = NO;
|
||||
strongSelfInMain.currentGiftView.isSelected = NO;
|
||||
}
|
||||
|
||||
/// 计算当前下标
|
||||
strongSelf.currentIndex = strongSelf.roundCount%giftMaxCount;
|
||||
strongSelfInMain.currentIndex = newCurrentIndex;
|
||||
strongSelfInMain.roundCount = roundCount;
|
||||
|
||||
/// 获取当前选中的view 并设置为选中状态
|
||||
QXSkyPraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
||||
giftView.isSelected = YES;
|
||||
QXSkyPraizeSubView *currentGiftView = strongSelfInMain.allViewsArray[newCurrentIndex];
|
||||
currentGiftView.isSelected = YES;
|
||||
|
||||
/// 重新赋值给选中view
|
||||
strongSelf.currentGiftView = giftView;
|
||||
strongSelfInMain.currentGiftView = currentGiftView;
|
||||
|
||||
if (strongSelf.roundCount / giftMaxCount == minRoundCount) {
|
||||
for (NSNumber *index in strongSelf.targetArrayIndex) {
|
||||
if (strongSelf.currentIndex == index.integerValue) {
|
||||
QXSkyPraizeSubView *giftView = strongSelf.allViewsArray[index.integerValue];
|
||||
giftView.isSelected = YES;
|
||||
giftView.resultView.hidden = NO;
|
||||
[giftView startPulseAnimationWithLayer];
|
||||
[strongSelf.targetArrayIndex removeObject:index];
|
||||
[strongSelf.finishTargetArrayIndex addObject:index];
|
||||
if (roundCount / giftMaxCount == minRoundCount) {
|
||||
for (NSNumber *index in targetArrayIndex) {
|
||||
if (newCurrentIndex == index.integerValue) {
|
||||
QXSkyPraizeSubView *targetGiftView = strongSelfInMain.allViewsArray[index.integerValue];
|
||||
targetGiftView.isSelected = YES;
|
||||
targetGiftView.resultView.hidden = NO;
|
||||
[targetGiftView startPulseAnimationWithLayer];
|
||||
|
||||
// 在主线程安全地修改数组
|
||||
[strongSelfInMain.targetArrayIndex removeObject:index];
|
||||
[strongSelfInMain.finishTargetArrayIndex addObject:index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
dispatch_source_set_timer(strongSelf.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, 0.03 * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
if (strongSelf.targetArrayIndex.count == 0) {
|
||||
strongSelf.isDrawing = NO;
|
||||
[strongSelf stopFastAnimate];
|
||||
[strongSelf animateFinishedSendGift];
|
||||
|
||||
dispatch_source_set_timer(strongSelfInMain.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, 0.03 * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
|
||||
if (strongSelfInMain.targetArrayIndex.count == 0) {
|
||||
strongSelfInMain.isDrawing = NO;
|
||||
[strongSelfInMain stopFastAnimate];
|
||||
[strongSelfInMain animateFinishedSendGift];
|
||||
}
|
||||
// }
|
||||
}else{
|
||||
strongSelf.delayTime = strongSelf.delayTime-0.02;
|
||||
if (strongSelf.delayTime <= 0.03) {
|
||||
strongSelf.delayTime = 0.03;
|
||||
} else {
|
||||
// 使用局部变量避免频繁访问属性
|
||||
NSTimeInterval delayTime = strongSelfInMain.delayTime - 0.02;
|
||||
if (delayTime <= 0.03) {
|
||||
delayTime = 0.03;
|
||||
}
|
||||
dispatch_source_set_timer(strongSelf.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, strongSelf.delayTime * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
strongSelfInMain.delayTime = delayTime;
|
||||
|
||||
dispatch_source_set_timer(strongSelfInMain.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, delayTime * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
dispatch_resume(_fastTimer);
|
||||
}
|
||||
-(void)animateFinishedSendGift{
|
||||
@@ -724,6 +748,13 @@ static NSInteger toSlowCount = 4;
|
||||
-(void)destroyViews{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
- (void)dealloc {
|
||||
if (_fastTimer) {
|
||||
dispatch_source_cancel(_fastTimer);
|
||||
_fastTimer = nil;
|
||||
}
|
||||
NSLog(@"%@ dealloc", NSStringFromClass([self class]));
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -568,74 +568,98 @@ static NSInteger toSlowCount = 4;
|
||||
dispatch_source_set_event_handler(_fastTimer, ^{
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
if (!strongSelf) return;
|
||||
|
||||
// 将需要的数据提前捕获到局部变量中
|
||||
__block NSInteger roundCount = strongSelf.roundCount;
|
||||
__block NSInteger currentIndex = strongSelf.currentIndex;
|
||||
NSArray *finishTargetArrayIndex = [strongSelf.finishTargetArrayIndex copy];
|
||||
NSMutableArray *targetArrayIndex = [strongSelf.targetArrayIndex mutableCopy];
|
||||
__block QXAgeDrawBtnType startType = strongSelf.startType;
|
||||
|
||||
// 如果需要更新UI,切换到主线程
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
strongSelf.roundCount++;
|
||||
if ((strongSelf.roundCount / giftMaxCount == minRoundCount) && strongSelf.startType != QXAgeDrawBtnTypeOne) {
|
||||
// 再次检查 strongSelf 是否存在
|
||||
__strong typeof(weakSelf) strongSelfInMain = weakSelf;
|
||||
if (!strongSelfInMain) return;
|
||||
|
||||
// 使用局部变量进行计算,避免频繁访问属性
|
||||
roundCount++;
|
||||
NSInteger newCurrentIndex = roundCount % giftMaxCount;
|
||||
|
||||
if ((roundCount / giftMaxCount == minRoundCount) && startType != QXSkyDrawBtnTypeOne) {
|
||||
BOOL has = NO;
|
||||
for (NSNumber *index in strongSelf.finishTargetArrayIndex) {
|
||||
if (index.integerValue == strongSelf.currentIndex) {
|
||||
for (NSNumber *index in finishTargetArrayIndex) {
|
||||
if (index.integerValue == currentIndex) {
|
||||
has = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.currentGiftView.isSelected = NO;
|
||||
|
||||
strongSelfInMain.currentGiftView.isSelected = NO;
|
||||
|
||||
QXAgePraizeSubView *giftView = strongSelfInMain.allViewsArray[newCurrentIndex];
|
||||
if (has) {
|
||||
QXAgePraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
||||
giftView.isSelected = YES;
|
||||
}else{
|
||||
QXAgePraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
||||
} else {
|
||||
giftView.isSelected = NO;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
/// 把上一个选中状态置为未选中
|
||||
strongSelf.currentGiftView.isSelected = NO;
|
||||
strongSelfInMain.currentGiftView.isSelected = NO;
|
||||
}
|
||||
|
||||
/// 计算当前下标
|
||||
strongSelf.currentIndex = strongSelf.roundCount%giftMaxCount;
|
||||
strongSelfInMain.currentIndex = newCurrentIndex;
|
||||
strongSelfInMain.roundCount = roundCount;
|
||||
|
||||
/// 获取当前选中的view 并设置为选中状态
|
||||
QXAgePraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
||||
giftView.isSelected = YES;
|
||||
QXAgePraizeSubView *currentGiftView = strongSelfInMain.allViewsArray[newCurrentIndex];
|
||||
currentGiftView.isSelected = YES;
|
||||
|
||||
/// 重新赋值给选中view
|
||||
strongSelf.currentGiftView = giftView;
|
||||
strongSelfInMain.currentGiftView = currentGiftView;
|
||||
|
||||
if (strongSelf.roundCount / giftMaxCount == minRoundCount) {
|
||||
for (NSNumber *index in strongSelf.targetArrayIndex) {
|
||||
if (strongSelf.currentIndex == index.integerValue) {
|
||||
QXAgePraizeSubView *giftView = strongSelf.allViewsArray[index.integerValue];
|
||||
giftView.isSelected = YES;
|
||||
giftView.resultView.hidden = NO;
|
||||
[giftView startPulseAnimationWithLayer];
|
||||
[strongSelf.targetArrayIndex removeObject:index];
|
||||
[strongSelf.finishTargetArrayIndex addObject:index];
|
||||
if (roundCount / giftMaxCount == minRoundCount) {
|
||||
for (NSNumber *index in targetArrayIndex) {
|
||||
if (newCurrentIndex == index.integerValue) {
|
||||
QXAgePraizeSubView *targetGiftView = strongSelfInMain.allViewsArray[index.integerValue];
|
||||
targetGiftView.isSelected = YES;
|
||||
targetGiftView.resultView.hidden = NO;
|
||||
[targetGiftView startPulseAnimationWithLayer];
|
||||
|
||||
// 在主线程安全地修改数组
|
||||
[strongSelfInMain.targetArrayIndex removeObject:index];
|
||||
[strongSelfInMain.finishTargetArrayIndex addObject:index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
dispatch_source_set_timer(strongSelf.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, 0.03 * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
if (strongSelf.targetArrayIndex.count == 0) {
|
||||
strongSelf.isDrawing = NO;
|
||||
[strongSelf stopFastAnimate];
|
||||
[strongSelf animateFinishedSendGift];
|
||||
|
||||
dispatch_source_set_timer(strongSelfInMain.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, 0.03 * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
|
||||
if (strongSelfInMain.targetArrayIndex.count == 0) {
|
||||
strongSelfInMain.isDrawing = NO;
|
||||
[strongSelfInMain stopFastAnimate];
|
||||
[strongSelfInMain animateFinishedSendGift];
|
||||
}
|
||||
// }
|
||||
}else{
|
||||
strongSelf.delayTime = strongSelf.delayTime-0.02;
|
||||
if (strongSelf.delayTime <= 0.03) {
|
||||
strongSelf.delayTime = 0.03;
|
||||
} else {
|
||||
// 使用局部变量避免频繁访问属性
|
||||
NSTimeInterval delayTime = strongSelfInMain.delayTime - 0.02;
|
||||
if (delayTime <= 0.03) {
|
||||
delayTime = 0.03;
|
||||
}
|
||||
dispatch_source_set_timer(strongSelf.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, strongSelf.delayTime * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
strongSelfInMain.delayTime = delayTime;
|
||||
|
||||
dispatch_source_set_timer(strongSelfInMain.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, delayTime * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
dispatch_resume(_fastTimer);
|
||||
}
|
||||
-(void)animateFinishedSendGift{
|
||||
|
||||
@@ -569,74 +569,98 @@ static NSInteger toSlowCount = 4;
|
||||
dispatch_source_set_event_handler(_fastTimer, ^{
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
if (!strongSelf) return;
|
||||
|
||||
// 将需要的数据提前捕获到局部变量中
|
||||
__block NSInteger roundCount = strongSelf.roundCount;
|
||||
__block NSInteger currentIndex = strongSelf.currentIndex;
|
||||
NSArray *finishTargetArrayIndex = [strongSelf.finishTargetArrayIndex copy];
|
||||
NSMutableArray *targetArrayIndex = [strongSelf.targetArrayIndex mutableCopy];
|
||||
__block QXTimeDrawBtnType startType = strongSelf.startType;
|
||||
|
||||
// 如果需要更新UI,切换到主线程
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
strongSelf.roundCount++;
|
||||
if ((strongSelf.roundCount / giftMaxCount == minRoundCount) && strongSelf.startType != QXTimeDrawBtnTypeOne) {
|
||||
// 再次检查 strongSelf 是否存在
|
||||
__strong typeof(weakSelf) strongSelfInMain = weakSelf;
|
||||
if (!strongSelfInMain) return;
|
||||
|
||||
// 使用局部变量进行计算,避免频繁访问属性
|
||||
roundCount++;
|
||||
NSInteger newCurrentIndex = roundCount % giftMaxCount;
|
||||
|
||||
if ((roundCount / giftMaxCount == minRoundCount) && startType != QXSkyDrawBtnTypeOne) {
|
||||
BOOL has = NO;
|
||||
for (NSNumber *index in strongSelf.finishTargetArrayIndex) {
|
||||
if (index.integerValue == strongSelf.currentIndex) {
|
||||
for (NSNumber *index in finishTargetArrayIndex) {
|
||||
if (index.integerValue == currentIndex) {
|
||||
has = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.currentGiftView.isSelected = NO;
|
||||
|
||||
strongSelfInMain.currentGiftView.isSelected = NO;
|
||||
|
||||
QXTimePraizeSubView *giftView = strongSelfInMain.allViewsArray[newCurrentIndex];
|
||||
if (has) {
|
||||
QXTimePraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
||||
giftView.isSelected = YES;
|
||||
}else{
|
||||
QXTimePraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
||||
} else {
|
||||
giftView.isSelected = NO;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
/// 把上一个选中状态置为未选中
|
||||
strongSelf.currentGiftView.isSelected = NO;
|
||||
strongSelfInMain.currentGiftView.isSelected = NO;
|
||||
}
|
||||
|
||||
/// 计算当前下标
|
||||
strongSelf.currentIndex = strongSelf.roundCount%giftMaxCount;
|
||||
strongSelfInMain.currentIndex = newCurrentIndex;
|
||||
strongSelfInMain.roundCount = roundCount;
|
||||
|
||||
/// 获取当前选中的view 并设置为选中状态
|
||||
QXTimePraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
||||
giftView.isSelected = YES;
|
||||
QXTimePraizeSubView *currentGiftView = strongSelfInMain.allViewsArray[newCurrentIndex];
|
||||
currentGiftView.isSelected = YES;
|
||||
|
||||
/// 重新赋值给选中view
|
||||
strongSelf.currentGiftView = giftView;
|
||||
strongSelfInMain.currentGiftView = currentGiftView;
|
||||
|
||||
if (strongSelf.roundCount / giftMaxCount == minRoundCount) {
|
||||
for (NSNumber *index in strongSelf.targetArrayIndex) {
|
||||
if (strongSelf.currentIndex == index.integerValue) {
|
||||
QXTimePraizeSubView *giftView = strongSelf.allViewsArray[index.integerValue];
|
||||
giftView.isSelected = YES;
|
||||
giftView.resultView.hidden = NO;
|
||||
[giftView startPulseAnimationWithLayer];
|
||||
[strongSelf.targetArrayIndex removeObject:index];
|
||||
[strongSelf.finishTargetArrayIndex addObject:index];
|
||||
if (roundCount / giftMaxCount == minRoundCount) {
|
||||
for (NSNumber *index in targetArrayIndex) {
|
||||
if (newCurrentIndex == index.integerValue) {
|
||||
QXTimePraizeSubView *targetGiftView = strongSelfInMain.allViewsArray[index.integerValue];
|
||||
targetGiftView.isSelected = YES;
|
||||
targetGiftView.resultView.hidden = NO;
|
||||
[targetGiftView startPulseAnimationWithLayer];
|
||||
|
||||
// 在主线程安全地修改数组
|
||||
[strongSelfInMain.targetArrayIndex removeObject:index];
|
||||
[strongSelfInMain.finishTargetArrayIndex addObject:index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
dispatch_source_set_timer(strongSelf.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, 0.03 * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
if (strongSelf.targetArrayIndex.count == 0) {
|
||||
strongSelf.isDrawing = NO;
|
||||
[strongSelf stopFastAnimate];
|
||||
[strongSelf animateFinishedSendGift];
|
||||
|
||||
dispatch_source_set_timer(strongSelfInMain.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, 0.03 * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
|
||||
if (strongSelfInMain.targetArrayIndex.count == 0) {
|
||||
strongSelfInMain.isDrawing = NO;
|
||||
[strongSelfInMain stopFastAnimate];
|
||||
[strongSelfInMain animateFinishedSendGift];
|
||||
}
|
||||
// }
|
||||
}else{
|
||||
strongSelf.delayTime = strongSelf.delayTime-0.02;
|
||||
if (strongSelf.delayTime <= 0.03) {
|
||||
strongSelf.delayTime = 0.03;
|
||||
} else {
|
||||
// 使用局部变量避免频繁访问属性
|
||||
NSTimeInterval delayTime = strongSelfInMain.delayTime - 0.02;
|
||||
if (delayTime <= 0.03) {
|
||||
delayTime = 0.03;
|
||||
}
|
||||
dispatch_source_set_timer(strongSelf.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, strongSelf.delayTime * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
strongSelfInMain.delayTime = delayTime;
|
||||
|
||||
dispatch_source_set_timer(strongSelfInMain.fastTimer,
|
||||
dispatch_time(DISPATCH_TIME_NOW, delayTime * NSEC_PER_SEC),
|
||||
DISPATCH_TIME_FOREVER,
|
||||
0.01 * NSEC_PER_SEC);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
dispatch_resume(_fastTimer);
|
||||
}
|
||||
-(void)animateFinishedSendGift{
|
||||
|
||||
Reference in New Issue
Block a user