Uipickerview项目工作背后 [英] Uipickerview behind item working

查看:47
本文介绍了Uipickerview项目工作背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图控制器中有pickerview.我通过添加到子视图中,然后更改子视图的框架来显示它.当我显示pickerview时,后面有一个按钮.当我在使pickerview无效之后单击那些区域时,仍会调用该按钮动作.如何正确设置pickerview?

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?

推荐答案

U子类如下所示的PickerView将帮助您解决此问题.

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

实施文件

//
//  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响应.当用户直接触摸主视图而不是选择器内容时,苹果通过这种方式通过返回nil来使主选择器视图对于用户触摸透明.

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.

这篇关于Uipickerview项目工作背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆