zoukankan      html  css  js  c++  java
  • IOS拖动

    http://blog.csdn.net/mamong/article/details/20831899

    代码资源

    #import "ViewController.h"

    @interface ViewController ()

    @property (nonatomic, strong) UIButton *btn;

    @end

    @implementation ViewController
    @synthesize btn;

    - (void)viewDidLoad
    {
    [super viewDidLoad];
    self.btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.btn.frame = CGRectMake(10, 10, 50, 50);

    [self.btn setTitle:@"触摸" forState:UIControlStateNormal];
    [self.btn setTitle:@"移动" forState:UIControlEventTouchDown];
    [self.btn addTarget:self action:@selector(dragMoving:withEvent: )forControlEvents: UIControlEventTouchDragInside];
    [self.btn addTarget:self action:@selector(dragEnded:withEvent: )forControlEvents: UIControlEventTouchUpInside |
    UIControlEventTouchUpOutside];

    [self.view addSubview:self.btn];
    }


    - (void) dragMoving: (UIControl *) c withEvent:ev
    {
    c.center = [[[ev allTouches] anyObject] locationInView:self.view];
    }

    - (void) dragEnded: (UIControl *) c withEvent:ev
    {
    c.center = [[[ev allTouches] anyObject] locationInView:self.view];
    }

    @end

  • 相关阅读:
    linux中~和/的区别
    Linux centos 7安装
    xshell远程连接虚拟机
    虚拟机Linux不能上网简单有效的解决办法
    visudo
    users
    TreeSizeFree(硬盘文件整理)
    dos2unix
    iconv
    PS1系统变量
  • 原文地址:https://www.cnblogs.com/wcLT/p/4198882.html
Copyright © 2011-2022 走看看