问题
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:
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.
来源:https://stackoverflow.com/questions/20970189/uipickerview-behind-item-working