Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iPhone OS 4.0中触摸图像视图时,如何编写图像视图的操作_Iphone_Uiimageview_Touch - Fatal编程技术网

在iPhone OS 4.0中触摸图像视图时,如何编写图像视图的操作

在iPhone OS 4.0中触摸图像视图时,如何编写图像视图的操作,iphone,uiimageview,touch,Iphone,Uiimageview,Touch,我想在导航栏中显示图像,而不是带有操作的后退按钮。现在我使用了图像视图,并在导航栏中显示了图像。现在我想在触摸或单击图像视图时为图像视图编写操作。是否可以为图像视图编写操作 我目前在iPhone OS 4.0中工作 请看 这是我的密码: UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0,5,40,40)]; [self.navigationController.navigationBar addSubview

我想在导航栏中显示图像,而不是带有操作的后退按钮。现在我使用了图像视图,并在导航栏中显示了图像。现在我想在触摸或单击图像视图时为图像视图编写操作。是否可以为图像视图编写操作

我目前在iPhone OS 4.0中工作

请看

这是我的密码:

     UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0,5,40,40)];
     [self.navigationController.navigationBar addSubview:view1];
     view1.backgroundColor = [UIColor clearColor];

     UIImage *img = [UIImage imageNamed:@"Back.png"];
     UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
     [view1 addSubview:imgView];

如何编写图像视图的操作?

在iOS 3.2之前,nou需要UIImageView的子类并实现触摸处理程序。 或者用自定义类型的UIButton替换UIImageView


使用iOS 3.2+,您可以高效地完成任务—只需将适当的视图添加到您的视图中即可。

不要直接将视图添加到导航栏,除非您准备在未来的操作系统版本中打破它

UIButton * b = [UIButton buttonWithType:UIButtonTypeCustom];
b.image = [UIImage imageNamed:@"Back.png"];
b.frame = (CGRect){{0,0},{40,40}};
[b addTarget:self action:@selection(wahatever) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:b] autorelease];