- (void)wobble {
static BOOL wobblesLeft = NO;
if (isShake) {
CGFloat rotation = (kWobbleRadians * M_PI) / 180.0;
CGAffineTransform wobbleLeft = CGAffineTransformMakeRotation(rotation);
CGAffineTransform wobbleRight = CGAffineTransformMakeRotation(-rotation);
[UIView beginAnimations:nil context:nil];
NSInteger i = 0;
NSInteger nWobblyButtons = 0;
// for (NSArray* buttonPage in _buttons) {
// for (TTLauncherButton* button in buttonPage) {
// if (button != _dragButton) {
// ++nWobblyButtons;
// if (i % 2) {
// button.transform = wobblesLeft ? wobbleRight : wobbleLeft;
//
// } else {
// button.transform = wobblesLeft ? wobbleLeft : wobbleRight;
// }
// }
// ++i;
// }
// }
for (UIView *tempView in [scrollView subviews]) {
if ([tempView isKindOfClass:[TestView class]] || [tempView isKindOfClass:[UIButton class]]) {
++nWobblyButtons;
if (i % 2) {
tempView.transform = wobblesLeft ? wobbleRight : wobbleLeft;
} else {
tempView.transform = wobblesLeft ? wobbleLeft : wobbleRight;
}
++i;
}
}
if (nWobblyButtons >= 1) {
[UIView setAnimationDuration:kWobbleTime];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(wobble)];
wobblesLeft = !wobblesLeft;
} else {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self performSelector:@selector(wobble) withObject:nil afterDelay:kWobbleTime];
}
[UIView commitAnimations];
}
}
- (void)startTimer {
isShake = YES;
if (shakeViewTimer == nil) {
shakeViewTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self
selector:@selector(wobble) userInfo:nil repeats:NO];
}
}
- (void)stopShake {
isShake = NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
// [UIView setAnimationDelegate:self];
for (UIView *tempView in [scrollView subviews]) {
tempView.transform = CGAffineTransformIdentity;
}
[UIView commitAnimations];
for (UIView *tempView in [scrollView subviews]) {
if ([tempView isKindOfClass:[UIButton class]]) {
[tempView removeFromSuperview];
}
}
}