zhengwenming / wmdragview Goto Github PK
View Code? Open in Web Editor NEWWMDragView致力于让任意View都可以自由悬浮拖曳(可拖动,悬浮按钮),类似于iOS的AssistiveTouch效果,微信浮窗。
License: MIT License
WMDragView致力于让任意View都可以自由悬浮拖曳(可拖动,悬浮按钮),类似于iOS的AssistiveTouch效果,微信浮窗。
License: MIT License
demo很棒,现在需求想实现微信视频聊天小窗口,这里怎么实现?大佬帮忙,感激不尽。
BUG触发流程:
1.创建控制控制器的子控件UIView,设置UIView的frame,例如:
UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(10, 40, 300, 100)];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
2.创建WMDragView *orangeView,使他成为redView的子控件,并在EndDragBlock设置和之前一样的frame, 例如:
WMDragView *orangeView = [[WMDragView alloc] initWithFrame:CGRectMake(130, 30, 40, 40)];
orangeView.backgroundColor = [UIColor orangeColor];
[redView addSubview:orangeView];
orangeView.EndDragBlock = ^(WMDragView *dragView){
dragView.frame=CGRectMake(130, 30, 40, 40);
};
3.当把orangeView拖出redView一段距离后释放手指,orangeView会向中间偏移一段距离才还原.
请问能尽可能修复这样的位移bug吗?
如果有多个按钮的时候,这个不好操作啊,被覆盖了,虽然有个点击的回调
初始化DragView给的Frame不在freeRect内,或者设置isKeepBounds,加载完成时必须要手动拖一下DragView,才能靠边或者正确显示在freeRect内,所以要重写两个方法,并主动调用一下[self keepBounds];就可以了
(void)setFreeRect:(CGRect)freeRect {
_freeRect = freeRect;
[self keepBounds];
}
(void)setIsKeepBounds:(BOOL)isKeepBounds {
_isKeepBounds = isKeepBounds;
[self keepBounds];
}
/**
拖动事件
@param pan 拖动手势
*/
-(void)dragAction:(UIPanGestureRecognizer *)pan{
if(self.dragEnable==NO)return;
switch (pan.state) {
case UIGestureRecognizerStateBegan:{//开始拖动
if (self.beginDragBlock) {
self.beginDragBlock(self);
}
//注意完成移动后,将translation重置为0十分重要。否则translation每次都会叠加
[pan setTranslation:CGPointZero inView:self];
//保存触摸起始点位置
self.startPoint = [pan translationInView:self];
break;
}
case UIGestureRecognizerStateChanged:{//拖动中
//计算位移 = 当前位置 - 起始位置
if (self.duringDragBlock) {
self.duringDragBlock(self);
}
CGPoint point = [pan translationInView:self];
float dx;
float dy;
switch (self.dragDirection) {
case WMDragDirectionAny:
{
if (self.isXuanHeng) {
dy = point.x - self.startPoint.x;
dx = self.startPoint.y - point.y;
} else {
dx = point.x - self.startPoint.x;
dy = point.y - self.startPoint.y;
}
}
break;
case WMDragDirectionHorizontal:
dx = point.x - self.startPoint.x;
dy = 0;
break;
case WMDragDirectionVertical:
dx = 0;
dy = point.y - self.startPoint.y;
break;
default:
dx = point.x - self.startPoint.x;
dy = point.y - self.startPoint.y;
break;
}
//计算移动后的view中心点
CGPoint newCenter = CGPointMake(self.center.x + dx, self.center.y + dy);
//移动view
self.center = newCenter;
// 注意完成上述移动后,将translation重置为0十分重要。否则translation每次都会叠加
[pan setTranslation:CGPointZero inView:self];
break;
}
case UIGestureRecognizerStateEnded:{//拖动结束
[self keepBounds];
if (self.endDragBlock) {
self.endDragBlock(self);
}
break;
}
default:
break;
}
}
isKeepBounds是不是又自动黏贴边界效果 应该是“isKeepBounds是不是有自动黏贴边界效果”
老哥,我调试发现WMDragView里面懒加载的imageView和button控件,即使我没有使用它们,它们还是被初始化了。调试发现问题出在layoutSubviews的时候你设置了它们的frame。而WMDragView里面的button的userInteractionEnabled是为NO的,这样就出现了一个问题,当我往WMDragView添加自定义button的时候,自定义button的点击事件就被拦截了。请问这种情况如何解决。
什么时候支持CocoaPods
进入下一个页面 再回来 会到初始位置
can you upload a sample using the video player?
这是一个优秀的作品,不过看过Demo后发现只能在单一页面内使用。
能否实现全局浮窗,切换页面不消失。
swift 如何使用 点击的回调 可不可以加图片 然后再加自定义View
WMDragView.gif中红色范围的拖动效果怎么在demo里面没有了?
因为有时候涉及到freeRect的临时变动,如果当前view在freeRect外,也不能会到freeRect内。
[dragSwichView.button setBackgroundImage:[UIImage imageNamed:@"icon_list"] forState:0];
图片颜色和透明度自动变浅
目前貌似互相有影响,多个的时候
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.