zoukankan      html  css  js  c++  java
  • 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);

    }

  • 相关阅读:
    bzoj2004(矩阵快速幂,状压DP)
    bzoj1242(弦图判定)
    uva1659(最大费用循环流)
    bzoj1009
    bzoj2893(费用流)
    bzoj4873(最大权闭合子图)
    bzoj2879(动态加边费用流)
    51nod 1239 欧拉筛模板
    poj2774 sa模版
    洛谷3391文艺平衡树
  • 原文地址:https://www.cnblogs.com/qingjoin/p/3626293.html
Copyright © 2011-2022 走看看