美文网首页
popoverPresentationController使用简

popoverPresentationController使用简

作者: 没打伞的鱼 | 来源:发表于2017-01-06 16:17 被阅读271次

- (void)didClickFliterBtn:(id)sender{
    
    NSLog(@"点击了==========筛选");
    
    UIView * sourceView = (UIView *)sender;
    
    UITableViewController *menuVC = [[UITableViewController alloc] init];
 __weak typeof(self)weakSelf = self;
    menuVC.tableView.delegate = weakSelf ;
    menuVC.tableView.dataSource = weakSelf ;
    menuVC.tableView.separatorStyle = UITableViewCellSeparatorStyleNone ;
    menuVC.tableView.rowHeight = 50 ;
    menuVC.tableView.backgroundColor =  [UIColorFromRGB(0xf9f9f9) colorWithAlphaComponent:0.1];
    
//    menuVC.view.backgroundColor= [UIColorFromRGB(0xf9f9f9) colorWithAlphaComponent:0.7];
    
    
    
    [menuVC.tableView registerClass:[DWHmenuCell class] forCellReuseIdentifier:@"menu"];

    
    // 设置大小
    menuVC.preferredContentSize = CGSizeMake(120, 50 * 3);
    // 设置 Sytle
    menuVC.modalPresentationStyle = UIModalPresentationPopover;//UIModalPresentationPopover;
    // 需要通过 sourceView 来判断位置的
    menuVC.popoverPresentationController.sourceView = sourceView;
    // 指定箭头所指区域的矩形框范围(位置和尺寸),以sourceView的左上角为坐标原点
    // 这个可以 通过 Point 或  Size 调试位置
    menuVC.popoverPresentationController.sourceRect = sourceView.bounds;
    
    menuVC.popoverPresentationController.backgroundColor = [UIColorFromRGB(0xf9f9f9) colorWithAlphaComponent:0.1];
    
    [UIColorFromRGB(0xf9f9f9) colorWithAlphaComponent:0.7];
    menuVC.popoverPresentationController.containerView.layer.shadowColor = [UIColorFromRGB(0xe9e1d2) CGColor];//阴影颜色
    menuVC.popoverPresentationController.containerView.layer.shadowOffset = CGSizeMake(0, 3);//width表示阴影与x的便宜量,height表示阴影与y值的偏移量
    menuVC.popoverPresentationController.containerView.layer.shadowOpacity = 0.08;//
    
    // 箭头方向
    menuVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
    // 设置代理
    menuVC.popoverPresentationController.delegate = self;
    
    //弹出筛选菜单
    [self presentViewController:menuVC animated:YES completion:nil];
        
}

//popover控制器是否点击后消失
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
    
    return YES;
}

//实现代理方法
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController*)controller{
    //返回UIModalPresentationNone为不匹配
    return UIModalPresentationNone;
}


//已经消失的时候调用
-(void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController* )popoverPresentationController{
    self.topView.filterBtn.selected = NO;
    
}



相关文章

网友评论

      本文标题:popoverPresentationController使用简

      本文链接:https://www.haomeiwen.com/subject/cfcxbttx.html