I'm trying to make a UIAlertView
shake. I already made the alertView
to stay on button click, but the shake animation is not working. Here is what I have:
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
self.direction = 1;
self.shakes = 0;
[self shake:aUIView];
}
}
-(void)shake:(UIAlertView *)theOneYouWannaShake
{
[UIView animateWithDuration:0.03 animations:^ {
theOneYouWannaShake.transform = CGAffineTransformMakeTranslation(5 * self.direction, 0);
}
completion:^(BOOL finished) {
if(self.shakes >= 10) {
theOneYouWannaShake.transform = CGAffineTransformIdentity;
return;
}
self.shakes++;
self.direction = self.direction * -1;
[self shake:theOneYouWannaShake];
}];
}
I tried putting an NSLog
in - (void)shake...
and I got an output. So there must be something wrong with my code as to why the alertView
isn't shaking.
I have created a illusion that makes alertview appear like it is shaking. Provided you must set the parameters about upto how much extent alertview(including that dark background screen) should shake.
Since you can't alter with the frames of UIAlertView so go down on CGTranformations.
I would recommend using Custom created UIAlertView instead, also there are few opensource libraries available.