BSDragView

BSDragView

  1. 一个实现了任意位置拖动的view
  2. 支持左右粘边,上下粘边效果

效果

在这里插入图片描述
gitHub地址:https://github.com/FreeBaiShun/BSDragView

用法

  1. 新创建一个自定义的view继承与BSDragView
  2. 直接使用这个自定义view即可支持任意位置拖动功能
//1. 自定义view
@interface MyView : BSDragView

@end

//2. 使用这个view
#import "ViewController.h"
#import "MyView.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(0, 100, 100, 100)];
    myView.backgroundColor = [UIColor blueColor];
    myView.isKeepBounds = YES;
    myView.isTopBottomKeepBounds = YES;
    [self.view addSubview:myView];
}
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DragLinearLayout是一个LinearLayout,&nbsp;他可是其子View在其范围内可拖动、可交换位置。默认情况下,子View是不可拖动的,你需要调用DragLinearLayout.setViewDraggable(child, child)方法让其可拖动。项目地址:https://github.com/justasm/DragLinearLayout 效果图:如何使用和使用LinearLayout一样: &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 2. 让子View可拖动默认情况下子View是不可拖动的,你需要调用dragLinearLayout.setViewDraggable()让子View变为可拖动的。DragLinearLayout&nbsp;dragLinearLayout&nbsp;=&nbsp;(DragLinearLayout)&nbsp;findViewById(R.id.container); //让子view可拖动,默认是不能拖动的 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(int&nbsp;i&nbsp;=&nbsp;1;&nbsp;i&nbsp;<&nbsp;dragLinearLayout.getChildCount();&nbsp;i ){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;View&nbsp;child&nbsp;=&nbsp;dragLinearLayout.getChildAt(i); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dragLinearLayout.setViewDraggable(child,&nbsp;child);&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}可以动态添加可拖动子viewfinal&nbsp;View&nbsp;view&nbsp;=&nbsp;View.inflate(context,&nbsp;R.layout.view_layout,&nbsp;null); dragLinearLayout.addDragView(view,&nbsp;view.findViewById(R.id.view_drag_handle)); &nbsp; //&nbsp;.. &nbsp; dragLinearLayout.removeDragView(view);使用OnViewSwapListener检测子view之间的排序变化事件:dragLinearLayout.setOnViewSwapListener(new&nbsp;DragLinearLayout.OnViewSwapListener()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;@Override &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;onSwap(View&nbsp;firstView,&nbsp;int&nbsp;firstPosition, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;View&nbsp;secondView,&nbsp;int&nbsp;secondPosition)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;update&nbsp;data,&nbsp;etc.. &nbsp;&nbsp;&nbsp;&nbsp;} });当在ScrollView中使用DragLinearLayout的时候,如果你想在拖拽的时候ScrollView也能滚动,需要调用setContainerScrollView(Scroll

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值