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

  • 相关阅读:
    XML文件详解以及解析
    Delphi 泛型详解
    Delphi 修改本地日期和时间
    java -> this关键字
    java ->super关键字
    Java -> 构造器(构造方法)
    java -> 方法的重载
    java面向对象->多态
    Java面向对象->接口
    Java面向对象->抽象类
  • 原文地址:https://www.cnblogs.com/wcLT/p/4198882.html
Copyright © 2011-2022 走看看