我有一个添加到 UIButton1 的 UIButton2:
操作@selector 仅在 UIButton2 与 UIButton1(“b”)相交的地方被调用。因此,在“a”或“c”区域中点击,操作方法 (addDockButtonTouchedDown) 不会被调用,但是当您在“b”部分中点击时会调用。这是一些代码:
// button1 is created elsewhere in the code and is a subclass of UIButton for UI layout (has a footer label and title label set). nothing fancy going on. button1 userInteractionEnabled is set to yes
// button2 is below...
NSString *dockPath = [[NSBundle mainBundle] pathForResource:@"AddToMyDock" ofType:@"png"];
UIImage *dockImage = [UIImage imageWithContentsOfFile:dockPath];
CGRect rect = CGRectMake(-20.0f, -10.0f + dockImage.size.height+1, dockImage.size.width, dockImage.size.height);
UIButton *button2 = [[UIButton alloc] initWithFrame:rect];
button2.userInteractionEnabled = YES;
button2.exclusiveTouch = YES;
[button2 setBackgroundImage:dockImage forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(addDockButtonTouchedDown:)
forControlEvents:UIControlEventTouchDown];
[button1 addSubview:button2];
任何想法为什么会发生这种情况以及如何解决它???请不要建议简单地使 button1 更大。