Uipickerview behind item working

2019-07-28 16:35发布

I have pickerview in my view controller. I am displaying it by adding into subview and then changing frame of subview. When my pickerview displayed I have one button behind it. When I click on those area after dispalying pickerview still that button action is called. How to set pickerview proper?

1条回答
在下西门庆
2楼-- · 2019-07-28 16:37

U subclass the PickerView like below will help u to fix this issue.

//
//  WPCustomPickerView.h
//  test
//
//  Created by VASANTH K on 08/01/14.
//  
//

#import <UIKit/UIKit.h>

@interface WPCustomPickerView : UIDatePicker

@end

implementation file

//
//  WPCustomPickerView.m
//  test
//
//  Created by VASANTH K on 08/01/14.
//  
//

#import "WPCustomPickerView.h"

@implementation WPCustomPickerView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    id hitview=[super hitTest:point withEvent:event];
     if(!hitview)
     {
     if(point.y<=self.frame.size.height&&point.y>=0)
     return self;
      }
return hitview;
}


@end

Here i override the hitTest to make UIPickerView response for the user interaction. This is the way how apple make main picker view transparent for user touch by return nil when user directly touch on the main view instead of picker content.

查看更多
登录 后发表回答