"长按实现视图抖动和删除"功能知识点整理
2011-07-07 11:32
471 查看
一、功能细分
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的使用
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的使用
相关文章推荐
- "长按实现视图抖动和删除"功能知识点整理
- GridView实现 "插入" 编辑更新删除功能
- GridView实现 "插入" 编辑更新删除功能
- iOS:删除storyBoard,纯代码实现UITabBarController的视图切换功能
- Android进阶笔记03:Android应用中实现查看"附近的人"的功能
- Safari 下用 "location.href = filePath" 实现下载功能的诡异 bug
- 如何在RecyclerView上面实现"拖放"和"滑动删除"-2
- 如何在RecyclerView上面实现"拖放"和"滑动删除"-2
- 用js实现下列功能,将给定的数字转化为千分位的格式,如把"10000"转化为"10,000",并考虑性能方面的因素
- 2. 为视图添加工具栏,实现新建,打开,删除的功能
- 如何在RecyclerView上面实现"拖放"和"滑动删除"-1
- oracle实现"limit"功能
- 转载:在MySql上实现MSSQL的"链接服务器"功能
- ExpandableListView实例(三)_实现QQ中"未分组"效果和"未分组"不可编辑删除功能
- c语言:模拟实现printf,要求功能:print("ccc\ts!",'b','i','t',"welcome to you");
- 不用JQuery,原生Javascript实现Ajax功能及相关知识点
- Javascript操纵DOM实现查找、删除、隔行换色等功能
- 一步步学习操作系统(2)——在STM32上实现一个可动态加载kernel的"my-boot"
- [掌盟+]RecycleView实现"英雄资料"页和"发现"页
- RecyclerView实现拖动排序和滑动删除功能