zoukankan      html  css  js  c++  java
  • popView

    1.设置代理

    <UIPopoverPresentationControllerDelegate>

    2.为它设置popView的灰色透明背景

    - (void)play:(UIButton *)sender {

        

        if (self.popVc == nil) {

            

            //创建一个遮罩

            UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, self.tableViewY, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];

            

            self.backView = backView;

            

            backView.backgroundColor = [UIColor blackColor];

            

            backView.alpha = 0;

            

            [self.view addSubview:backView];

            

            [UIView animateWithDuration:0.5 animations:^{

            

                backView.alpha = 0.6;

                

            }];

            

        }

        UUPopViewController * popVc = [[UUPopViewController alloc]init];

        self.popVc = popVc;

        

        popVc.modalPresentationStyle =  UIModalPresentationPopover;

        

        popVc.popDelegate = self;

        

        popVc.preferredContentSize = CGSizeMake(200, 100);

        

        UIPopoverPresentationController *popPreVc = popVc.popoverPresentationController;

        

        self.popPreVc = popPreVc;

        

        popPreVc.sourceView = sender;

        

        popPreVc.permittedArrowDirections = UIPopoverArrowDirectionUp;

        popPreVc.sourceRect = CGRectMake(10, 45, 0, 0);

        

        popPreVc.delegate = self;

        

        [self presentViewController:popVc animated:YES completion:nil];

        

    }

     3.为了防止backView的y跟着tableView进行滚动

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{

        self.tableViewY = scrollView.contentOffset.y;

    }

    4.在popView消失的代理方法里面将背景视图进行消除

    -(void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{

        

         self.popVc = nil;

        

        [UIView animateWithDuration:0.2 animations:^{

            

            self.backView.alpha = 0;

            

        } completion:^(BOOL finished) {

            

            [self.backView removeFromSuperview];

        }];

    }

    5.此外popView的里面的控制器里面应不能直接控制当前控制器的背景视图的产生,所以应该使用代理,点击时清空背景,清空自己

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

        

        [self dismissViewControllerAnimated:YES completion:nil];

        

        if ([self.popDelegate respondsToSelector:@selector(dismissPopViewAndBackview:)]) {

            [self.popDelegate dismissPopViewAndBackview:self];

        }

    }

    6.当前控制器应当成为这个控制器的代理,并实现代理方法

    - (void)dismissPopViewAndBackview:(UUPopViewController *)popVc{    

        [self popoverPresentationControllerDidDismissPopover:self.popPreVc];

    }

    7.此外还要设置popView的类型(全屏,从64开始等等)

    - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{

        return UIModalPresentationNone;

    }

  • 相关阅读:
    StrToUnicode C#语言如何将汉字转换成Unicode字符
    SQLServer 2008数据库查看死锁、堵塞的SQL语句
    String.IsNullOrEmpty和"".length>0 那个更高效
    使用策略设计模式,反射,解决商城系统中的商品折扣问题
    假分页
    MAC校验
    eclipse环境加载svn
    将数据导出Excel格式
    svn提交问题
    字符串前拼接字符
  • 原文地址:https://www.cnblogs.com/chaoyueME/p/5937699.html
Copyright © 2011-2022 走看看