Iphone 如何从iAction方法访问视图
我在一个窗口中有4个视图。指向同一方法的所有视图链接-(iAction)已触摸:(id)发件人 当触摸视图1时,如何使视图1的背景颜色发生变化。 但左3视图不是。 另外,如果我触摸另一个视图,只会看到触摸会改变背景颜色,但其他视图不会改变Iphone 如何从iAction方法访问视图,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我在一个窗口中有4个视图。指向同一方法的所有视图链接-(iAction)已触摸:(id)发件人 当触摸视图1时,如何使视图1的背景颜色发生变化。 但左3视图不是。 另外,如果我触摸另一个视图,只会看到触摸会改变背景颜色,但其他视图不会改变 谢谢你你应该实现你的UIViewController的-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event方法 -(void)touchesBegan:(NSSet *)touches withEve
谢谢你你应该实现你的
UIViewController的-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event
方法
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if([event touchesForView:view1] != nil)
//View1 touched
else if ([event touchesForView:view2] != nil)
//View2 touched
else if ([event touchesForView:view3] != nil)
//View3 touched
else if ([event touchesForView:view4] != nil)
//View4 touched
}
您可以通过设置视图的“tag”属性来标记视图,并在(iAction)toucted:(id)sender中检查标记值,如
if (((UIView*)sender).tag == 1) {
//Do something for the view with tag value 1
}