Decir que tengo este código:¿Cómo hacer que un botón de intercepción de superview toque eventos?
#import <UIKit/UIKit.h>
@interface MyView : UIView
@end
@implementation MyView
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// How can I get this to show up even when the button is touched?
NSLog(@"%@", [touches anyObject]);
}
@end
@interface TestViewAppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
}
@end
@implementation TestViewAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MyView *view = [[MyView alloc] initWithFrame:[window frame]];
[view setBackgroundColor:[UIColor whiteColor]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Hiya!" forState:UIControlStateNormal];
[button setFrame:CGRectMake(100.0, 100.0, 200.0, 200.0)];
[view addSubview:button];
[window addSubview:view];
[window makeKeyAndVisible];
}
- (void)dealloc
{
[window release];
[super dealloc];
}
@end
¿Hay alguna manera de interceptar los eventos de toque enviadas a su botón? Lo que me gustaría hacer finalmente es crear una subclase UIView que diga a su controlador de vista (o delegar, lo que sea) cuando detecte un deslizamiento para poder "empujar" el siguiente controlador de vista a la pila (similar a la pantalla de inicio del iPhone) Pensé que este era el primer paso, pero estoy abierto a sugerencias si me estoy acercando a esto incorrectamente.
no te refieres a return [superview hitTest: point withEvent: event]; –
'super' es correcto porque querrá llamar al método de clases clase principal,' superview' omitirá esto. – keegan3d