-(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 按钮拖动。的更多相关文章

  1. iOS 按钮倒计时功能

    iOS 按钮倒计时功能, 建议把按钮换成label,这样会避免读秒时闪烁 __block ; __block UIButton *verifybutton = _GetverificationBtn; ...

  2. 优秀前端工程师必备: (总结) 清除原生ios按钮样式

    写移动端的web开发时, 需要清除IOS本身的各种样式: 1.消除ios按钮原生样式, 给按钮加自定义样式: input[type="button"], input[type=&q ...

  3. IOS UITableView拖动排序功能

    UITbableView作为列表展示信息,除了展示的功能,有时还会用到删除,排序等功能,下面就来讲解一下如何实现排序. 排序是当表格进入编辑状态后,在单元格的右侧会出现一个按钮,点击按钮,就可以拖动单 ...

  4. iOS按钮设置图片在上文字在下

    UIButton同时设置Title和Image后,默认是图片在左文字在右,如下图1,很多情况下我们希望图片在上图片在下,如下图2,只需要简单的几行代码,即可实现. (1)因为需要处理多个按钮,所以将实 ...

  5. ios 按钮点击无反应

    今天项目遇到有个UIButton无法点击,弄了半天,总结出以下几个结论 1.如果一个UIButton的frame超出父视图的frame,UIButton还是可以显现的,但响应不了点击事件了,当开发中, ...

  6. iOS 按钮小知识点总结

    //设置按钮里面图片和文字的间距 btn.titleEdgeInsets=UIEdgeInsetsMake(0, 20, 0, 0); button.imageEdgeInsets = UIEdgeI ...

  7. 20150506—WinForm自动生成按钮&按钮拖动

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  8. ios 按钮常见属性

    1.UIButton状态: UIControlStateNormal          // 正常状态    UIControlStateHighlighted     // 高亮状态    UICo ...

  9. iOS按钮的基本使用代码优化

    将图片按钮进行连线, 声明方法同时连接六个按钮 -(void)move:(UIButton *)btn{ //    NSLog(@"看见一个美女"); //头尾式动画 //0.开 ...

随机推荐

  1. 解决iframe加载的内容有时显示有时不显示

    在ASP.NET MVC项目中遇到了这样的一个问题,假设父页面有一个iframe <iframe id=" width="100%" height="10 ...

  2. AutoMapper在MVC中的运用02-Decimal转String、集合、子父类映射

    本篇AutoMapper使用场景: ※ Decimal转换成String类型 ※ 源数组转换成目标数组 ※ 源中的集合(数组)属性转换成目标中的集合(数组)属性 ※ 子类父类间的映射 Decimal转 ...

  3. Android SDK代理服务器解决国内不能更新下载问题

    原文地址:http://blog.csdn.net/boonya/article/details/38752647 读者须知:本篇文章中最靠谱的是第三种方式,最近有读者反映第三种方式也不行了,下面提供 ...

  4. windows7文件共享 详细步骤 图解

    windows7文件共享详细步骤图解 http://wenku.baidu.com/link?url=PROjBfZ0KZFiAlgpb6sdaZBnSzFNTx3Ui_YXs5-IVoKBf2pPN ...

  5. android的logcat详细用法!

    from://http://www.miui.com/article-272-1.html [技术交流]android的logcat详细用法! logcat是Android中一个命令行工具,可以用于得 ...

  6. POP缩放动画

    POP缩放动画 效果 源码 https://github.com/YouXianMing/Animations // // SpringScaleViewController.m // Animati ...

  7. 蓝精灵:寻找神秘村Smurfs: The Lost Village迅雷下载

    蓝妹妹(黛米·洛瓦托 Demi Lovato 配音)发现了一张遗落的地图,由此引发精灵们对于神秘村庄真实性的猜想.于是,满怀好奇心的蓝妹妹与聪聪(丹尼·朴迪 Danny Pudi 配音).笨笨(杰克· ...

  8. Java比较两个Date日期的大小

    import java.util.*; import java.text.ParseException; import java.text.SimpleDateFormat; class Test{ ...

  9. docker logs-查看docker容器日志

    只限制最后100条的日志,并持续更新日志显示 docker logs -f --tail= CONTAINER_ID docker logs -f --tail CONTAINER_ID   http ...

  10. const 变量修饰 研究

    #include<stdio.h> #include<iostream> using namespace std; struct A { ;} ;} }; int main() ...