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);

    }

  • 相关阅读:
    区分jquery中的offset和position
    如何让搜索框的键盘显示搜索按键?
    如何设置table的border-radius?
    如何让输入框自动使用英文输入法?
    如何隐藏数字输入框的上下箭头?
    autocapticalize和autocorrect
    防止注入
    sychronized和lock和区别
    各大公司Java面试题超详细总结
    n的阶乘
  • 原文地址:https://www.cnblogs.com/qingjoin/p/3626293.html
Copyright © 2011-2022 走看看