iOS 按钮拖动。
-(void)testMove
{
moveBtn = [[UIButton alloc ]init];
moveBtn.frame = CGRectMake(0, 30, 60, 60);
moveBtn.backgroundColor = [UIColorredColor];
//[moveBtn addTarget:self action:@selector(moveBtn) forControlEvents:UIControlEventTouchDown];
//[moveBtn addTarget:self action:@selector(moveBtnEnd) forControlEvents:UIControlEventTouchUpInside];
[moveBtnaddTarget:selfaction:@selector(dragMoving:withEvent: )forControlEvents: UIControlEventTouchDragInside];
[moveBtnaddTarget:selfaction:@selector(doClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:moveBtn];
}
- (void) dragMoving: (UIButton *)btn withEvent:(UIEvent *)event
{
CGPoint point = [[[event allTouches] anyObject] locationInView:self.view];
CGFloat x = point.x;
CGFloat y = point.y;
CGFloat btnx = btn.frame.size.width/2;
CGFloat btny = btn.frame.size.height/2;
if(x<=btnx)
{
point.x = btnx;
}
if(x >= self.view.bounds.size.width - btnx)
{
point.x = self.view.bounds.size.width - btnx;
}
NSLog(@"fs:%f %f",x, btnx);
btn.center = point;
NSLog(@"%f,,,%f",btn.center.x,btn.center.y);
}
iOS 按钮拖动。的更多相关文章
- iOS 按钮倒计时功能
iOS 按钮倒计时功能, 建议把按钮换成label,这样会避免读秒时闪烁 __block ; __block UIButton *verifybutton = _GetverificationBtn; ...
- 优秀前端工程师必备: (总结) 清除原生ios按钮样式
写移动端的web开发时, 需要清除IOS本身的各种样式: 1.消除ios按钮原生样式, 给按钮加自定义样式: input[type="button"], input[type=&q ...
- IOS UITableView拖动排序功能
UITbableView作为列表展示信息,除了展示的功能,有时还会用到删除,排序等功能,下面就来讲解一下如何实现排序. 排序是当表格进入编辑状态后,在单元格的右侧会出现一个按钮,点击按钮,就可以拖动单 ...
- iOS按钮设置图片在上文字在下
UIButton同时设置Title和Image后,默认是图片在左文字在右,如下图1,很多情况下我们希望图片在上图片在下,如下图2,只需要简单的几行代码,即可实现. (1)因为需要处理多个按钮,所以将实 ...
- ios 按钮点击无反应
今天项目遇到有个UIButton无法点击,弄了半天,总结出以下几个结论 1.如果一个UIButton的frame超出父视图的frame,UIButton还是可以显现的,但响应不了点击事件了,当开发中, ...
- iOS 按钮小知识点总结
//设置按钮里面图片和文字的间距 btn.titleEdgeInsets=UIEdgeInsetsMake(0, 20, 0, 0); button.imageEdgeInsets = UIEdgeI ...
- 20150506—WinForm自动生成按钮&按钮拖动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- ios 按钮常见属性
1.UIButton状态: UIControlStateNormal // 正常状态 UIControlStateHighlighted // 高亮状态 UICo ...
- iOS按钮的基本使用代码优化
将图片按钮进行连线, 声明方法同时连接六个按钮 -(void)move:(UIButton *)btn{ // NSLog(@"看见一个美女"); //头尾式动画 //0.开 ...
随机推荐
- hdu1716排列2(stl:next_permutation+优先队列)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- uifont 字体详解
时间2013-06-04 11:26:33 CSDN博客原文 http://blog.csdn.net/u010013695/article/details/9020611 我们在开发中很多时候要设 ...
- 如何:为iOS 的方法写注释 让xcode 能够索引得到?
如何:为iOS 的方法写注释 让xcode 能够索引得到? 按照如下方法为ios项目写注释: 将会让xcode能够索引得到如下结果:
- .NET:注意 Primitive 这个小坑
背景 有个需求,需要递归遍历类型的所有属性(属性的属性),然后对不同的类型做不同的处理,或者只是将类型分为三类:Primitive.Complex 和 Collection.因为 MS 的 Type ...
- Android之取消ViewPage+Fragment的预加载
用过ViewPage+Fragment组合的童鞋自然知道这个问题,没有遇到的同学祝愿你们永远不会遇到,呵呵.直接上关键代码 注释:setUserVisibleHint每次fragment显示与隐藏都会 ...
- Android之关于MAC把java7改为java6的方法
先来个草草草,某天手贱有java6升级为java7了,然后用ant打包发布,然后再一次草草草,居然有冲突勒,网上找了一堆...无果,最后想起直接在.bash_profile上配置环境试试吧,居然通了, ...
- centos7更改为启动桌面或命令行模式
进入cenos7的命令行模式 终端输入“init 3”回车进入命令行模式 登录成功后 # systemctl get-default //获取当前系统启动模式 查看配置文件 # cat /etc/in ...
- MVC详解(转)
原文链接:MVC详解 MVC与模板概念的理解 MVC(Model View Controller)模型-视图-控制器 MVC本来是存在于Deskt op程序中的,M是指数据模型,V是指用户界面,C ...
- qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""
转载:https://forum.qt.io/topic/97484/qt-5-12-make-mingw-32-release/12 I build Qt 5.12 with MinGW 7.3.0 ...
- MyBatis动态SQL foreach标签实现批量插入
需求:查出给定id的记录: <select id="getEmpsByConditionForeach" resultType="com.test.beans.Em ...