[英]How to call a UIView method in my UIViewController?
I have a method to create a rectangle in my custom uiview and I want to call it in my UIViewController.I am trying to use UITapGestureRecognizer in my UIViewController and check if a point in the rectangle is called. 我有一个在自定义uiview中创建矩形的方法,我想在UIViewController中调用它。我试图在UIViewController中使用UITapGestureRecognizer并检查是否调用了矩形中的一个点。
rectangle in my custom uiview ( myView.m ) 我的自定义uiview中的矩形(myView.m)
- (CGRect) myRect
{
return CGRectMake(10, 10, self.bounds.size.height - 20, self.bounds.size.height - 20);
}
UITapGestureRecognizer method in my MyViewController.m MyViewController.m中的UITapGestureRecognizer方法
- (void)viewDidLoad
{
[super viewDidLoad];
[self.PlayDraw setNeedsDisplay];
}
- (IBAction)handleTap:(UITapGestureRecognizer *)sender {
CGPoint point = [sender locationInView:self.view];
if(CGRectContainsPoint([self.PlayDraw myRect],point)) {
NSLog(@"touched");
}
and I get an error for [self.PlayDraw myRect] that says 我收到[self.PlayDraw myRect]的错误消息,内容为
No visible @interface for 'MyViewController' declares the selector 'myRect' 'MyViewController'没有可见的@interface声明选择器'myRect'
and here is my MyViewController.h 这是我的MyViewController.h
@interface MyViewController : UIViewController
{
}
- (IBAction)handleTap:(UITapGestureRecognizer *)sender;
@property (strong, nonatomic) IBOutlet myView *PlayDraw;
@end
In your myView.h file add: 在您的myView.h文件中添加:
- (CGRect) myRect;
You have to expose this method to other classes. 您必须将此方法公开给其他类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.