一、功能细分
1、对视图添加长按手势的识别:{ UILongPressGestureRecognizer类的使用}
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPressRecognizer.allowableMovement = 30;
[testView addGestureRecognizer:longPressRecognizer];
[longPressRecognizer release];
2、删除一个视图后,改变其它视图的位置,可以通过修改其center的值来实现:
如 tempView.center = tempViewCenter;
3、抖动的实现:{修改view的 transform值来改变视图的旋转过的角度;通过动画来实现动态角度转动;当动画结束后再时其转动相反角度,也动画实现,如此反复即可。}
- (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 (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];
}
}
4、停止抖动:
tempView.transform = CGAffineTransformIdentity;
二、知识点整理
1、
UIGestureRecognizer 手势识别类
2、
NSValue的使用
3、
CGAffineTransform
CGFloat rotation = (kWobbleRadians * M_PI) / 180.0;
CGAffineTransform wobbleLeft = CGAffineTransformMakeRotation(rotation);
CGAffineTransform wobbleRight = CGAffineTransformMakeRotation(-rotation);
tempView.transform = CGAffineTransformIdentity;
4、UIView类中一些不常用到的内容
如:uiview.transform
5、NSObject类中一些不常用的内容
如:[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self performSelector:@selector(wobble) withObject:nil afterDelay:kWobbleTime];
6、NSTimer的使用