在iPhone OS 4.0中触摸图像视图时,如何编写图像视图的操作
我想在导航栏中显示图像,而不是带有操作的后退按钮。现在我使用了图像视图,并在导航栏中显示了图像。现在我想在触摸或单击图像视图时为图像视图编写操作。是否可以为图像视图编写操作 我目前在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
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];