iOS 做下拉框列表

首先建一个popviewcontroller,实现数据写一个代理回调。在跳转之前设置contorller的frame.然后背景设置透明度,tableview 滚动enabled设置


- (IBAction)selectRightItem:(UIBarButtonItem*)sender

{

if(_backgroudView!=nil) {

[selfviewWillDisappear:YES];

return;

}

_tableView.scrollEnabled=NO;

//pop.modalPresentationStyle = UIModalPresentationPopover;

//UIPopoverPresentationController *popVC = pop.popoverPresentationController;

//popVC.delegate = self;

//popVC.barButtonItem = sender;

pop.delegate=self;

pop.view.frame=CGRectMake(SCREENWIDTH-10-134,64,134,7*44);

_backgroudView=[[BackgroudViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];

[_backgroudViewsetBackgroundColor:[UIColorcolorWithWhite:0.0alpha:0.4]];

[_backgroudViewaddSubview:pop.view];

UITapGestureRecognizer*tapgestureRecognizer=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(viewWillDisappear:)];

tapgestureRecognizer.delegate=self;

[_backgroudViewaddGestureRecognizer:tapgestureRecognizer];

[self.view.windowaddSubview:_backgroudView];

}

-(void)popoverViewdidSelectRowAtIndex:(NSInteger)index

{

NSLog(@"index=====%d",index);

[selfviewWillDisappear:YES];

}

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

//{

//return UIModalPresentationNone;

//}

-(void)viewWillDisappear:(BOOL)animated

{

_tableView.scrollEnabled=YES;

[_backgroudViewremoveFromSuperview];

_backgroudView=nil;

}

-(void)touchesBegan:(NSSet<UITouch*> *)touches withEvent:(UIEvent*)event

{

}

-(BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch{

if([touch.viewisDescendantOfView:pop.view]) {

returnNO;

}

returnYES;

}

-(void)scrollViewDidScroll:(UIScrollView*)scrollView

{

scrollViewY=scrollView.contentOffset.y;

NSLog(@"scrollViewY======%f",scrollViewY);

}

你可能感兴趣的:(iOS 做下拉框列表)