需求 - 5 - 悬浮框 - 3
来源:互联网 发布:ubuntu gnome dock 编辑:程序博客网 时间:2024/05/18 00:44
前两介绍了两种实现,分别是:
1.通过添加手势,判断UIGestureRecognizerState的状态来实现
2.通过重新UIControl的触摸事件
这里介绍UIButton作为UIControl的子类的另外一种实现方法:
#import "LBSuspensionFrameFiveViewController.h"@interface LBSuspensionFrameFiveViewController ()@property (nonatomic, strong) UIButton *dragFloatView;@end@implementation LBSuspensionFrameFiveViewController- (void)viewDidLoad{ [super viewDidLoad]; [self.view setBackgroundColor:[UIColor whiteColor]]; self.dragFloatView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 80)]; [self.dragFloatView setImage:[UIImage imageNamed:@"onion.png"] forState:UIControlStateNormal]; [self.dragFloatView setShowsTouchWhenHighlighted:YES]; //去掉灰亮 [self.dragFloatView addTarget:self action:@selector(dragBegan:withEvent:) forControlEvents:UIControlEventTouchDown]; [self.dragFloatView addTarget:self action:@selector(dragMoving:withEvent:) forControlEvents:UIControlEventTouchDragInside]; [self.dragFloatView addTarget:self action:@selector(dragEnded:withEvent:) forControlEvents: UIControlEventTouchUpInside | UIControlEventTouchUpOutside]; [self.view addSubview:self.dragFloatView];}- (void) dragBegan: (UIControl *) c withEvent:ev{ NSLog(@"Button moving bagin ......"); }- (void) dragMoving: (UIControl *) c withEvent:ev{ NSLog(@"Button is moving .............."); c.center = [[[ev allTouches] anyObject] locationInView:self.view];}- (void) dragEnded: (UIControl *) c withEvent:ev{ NSLog(@"Button moving end.............."); // 如果需要随即停顿.// c.center = [[[ev allTouches] anyObject] locationInView:self.view]; [self moveToEdge];}- (void)moveToEdge{ if (self.dragFloatView.center.x <= self.dragFloatView.superview.bounds.size.width * 0.5){ [UIView animateWithDuration:0.7 animations:^{ self.dragFloatView.center = CGPointMake(self.dragFloatView.bounds.size.width * 0.5, self.dragFloatView.center.y); }]; } else{ [UIView animateWithDuration:0.7 animations:^{ self.dragFloatView.center = CGPointMake(self.dragFloatView.superview.bounds.size.width - self.dragFloatView.bounds.size.width*0.5, self.dragFloatView.center.y); }]; }}@end
0 0
- 需求 - 5 - 悬浮框 - 3
- 需求 - 5 - 悬浮框 - 1
- 需求 - 5 - 悬浮框 - 2
- 悬浮框
- 悬浮框
- 悬浮框
- Android悬浮框应用--悬浮笔记
- [Javascript]右侧悬浮框
- 标题悬浮提示框
- Android 桌面悬浮框
- div悬浮提示框
- Android 桌面悬浮框
- Extjs添加悬浮框
- jquery悬浮提示框
- Android桌面悬浮框
- android 悬浮框
- 网站 图片 悬浮框
- 可移动悬浮框
- Mysql之运算的使用
- VC 串口通信实现方式
- 初学php(一)
- 理解Java中的IO
- MAT 格式操作
- 需求 - 5 - 悬浮框 - 3
- javascript的window.ActiveXObject对象,区别浏览器的方法
- Win8下Android SDK的安装与环境变量配置
- LINUX 下安装 jdk 问题(please use alien to install rpm packages on Debian )
- 深入浅出 React Native:使用 JavaScript 构建原生应用
- 本地化下按首字母分组排序的神器——UILocalizedIndexedCollation
- 通用正则匹配
- AR资料
- POJ 3050 Hopscotch