项目工作背后的Uipickerview

我在我的视图控制器pickerview 。 我显示它通过添加到子视图,然后更改子视图的框架。 当我的pickerview显示我有一个button后面。 当我点击这些区域后,仍然显示button动作调用pickerview 。 如何设置pickerview正确?

U子类PickerView如下所示将帮助你解决这个问题。

 // // WPCustomPickerView.h // test // // Created by VASANTH K on 08/01/14. // // #import <UIKit/UIKit.h> @interface WPCustomPickerView : UIDatePicker @end 

实施文件

 // // 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 

在这里我重写hitTest来为用户交互做UIPickerView响应。 这就是苹果如何让主select器视图对用户触摸透明,当用户直接触摸主视图而不是select器内容时,返回零。