仿新版微信浮窗效果

阅读公众号或其他文章,经常需要暂时退出文章.
在新版微信中,可以把浏览的文章缩小为浮窗.点击浮窗继续阅读.对于经常在微信里阅读的人来说,这简直就是人类之光.

微信效果如下




微信效果

对于这功能我进行了仿写.
效果如下

仿写效果

微信的大佬一定用了了不起的技术,我这里只是实现效果.


简单写了一个库,一句代码即可实现效果
https://github.com/SherlockQi/WeChatFloat

//在AppDelegate中将类名传入即可
[HKFloatManager addFloatVcs:@[@"HKSecondViewController"]];


使用到的技术点

监听侧滑返回
//设置边缘侧滑代理
self.navigationController.interactivePopGestureRecognizer.delegate = self;

//当开始侧滑pop时调用此方法
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    /* 判断是否开启边缘侧滑返回 **/
    if (self.navigationController.viewControllers.count > 1) {
         [self beginScreenEdgePanBack:gestureRecognizer];
        return YES;
    }
    return NO;
}
/* UIScreenEdgePanGestureRecognizer
@property(nullable, nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
/*! This subclass of UIPanGestureRecognizer only recognizes if the user slides their finger
    in from the bezel on the specified edge. */
//NS_CLASS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED @interface UIScreenEdgePanGestureRecognizer : UIPanGestureRecognizer
**/
//利用CADisplayLink 来实现监听返回手势
- (void)beginScreenEdgePanBack:(UIGestureRecognizer *)gestureRecognizer{
         /*
          * 引用 gestureRecognizer
          * 开启 CADisplayLink
          * 显示右下视图
          **/
    self.edgePan = (UIScreenEdgePanGestureRecognizer *)gestureRecognizer;
    _link = [CADisplayLink displayLinkWithTarget:self selector:@selector(panBack:)];
    [self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
    [[UIApplication sharedApplication].keyWindow addSubview:self.floatArea];
}
//此方法中进行操作
- (void)panBack:(CADisplayLink *)link {
    //判断手势状态
    if (self.edgePan.state == UIGestureRecognizerStateChanged) {//移动过程
       /*
        * 改变右下视图 frame
        * 判断手指是否进入右下视图中
        **/
    //手指在屏幕上的位置    
    CGPoint tPoint =  [self.edgePan translationInView:kWindow];
     ...根据tPoint设置右下视图 frame...
    //手指在右下视图上的位置(若 x>0 &
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值