zoukankan      html  css  js  c++  java
  • iOS 悬浮可移动按钮

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(100, 100, 50, 50);
        btn.backgroundColor = [UIColor yellowColor];
        btn.clipsToBounds = YES;
        btn.layer.cornerRadius = 25;
        btn.tag = 10086;
        [self.view addSubview:btn];
        
        //添加手势
        //添加移动的手势
        UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(locationChange:)];
        pan.delaysTouchesBegan = YES;
        [btn addGestureRecognizer:pan];
        
    }
    
    - (void)locationChange:(UIPanGestureRecognizer *)recognizer
    {
        
        CGPoint translation = [recognizer translationInView:self.view];
        
        CGFloat centerX=recognizer.view.center.x+ translation.x;
        
        CGFloat thecenter=0;
        
        recognizer.view.center=CGPointMake(centerX,
                                           
                                           recognizer.view.center.y+ translation.y);
        
        [recognizer setTranslation:CGPointZero inView:self.view];
        
        if(recognizer.state==UIGestureRecognizerStateEnded|| recognizer.state==UIGestureRecognizerStateCancelled) {
            
            if(centerX>ScreenWidth/2) {
                
                thecenter=ScreenWidth-50;
                
            }else{
                
                thecenter=50;
                
            }
            [UIView animateWithDuration:0.3 animations:^{
                
                recognizer.view.center=CGPointMake(thecenter,
                                                   
                                                   recognizer.view.center.y+ translation.y);
                
            }];
            
        }
        
    
    }
  • 相关阅读:
    Delphi Help
    RAD 10 新控件 TSearchBox TSplitView
    滚动条
    c++builder Active Form
    chart左侧
    RAD 10 蓝牙
    浏览器插件 火狐插件
    c++builder delphi 调用dll dll编写
    模拟键盘 键盘虚拟代码
    oracle怎么把一个用户下的表复制给另一个用户?(授予表权限)
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/6141093.html
Copyright © 2011-2022 走看看