Uipickerview behind item working

落爺英雄遲暮 提交于 2020-01-16 04:33:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!