Nói rằng tôi có mã này:Làm cách nào để tạo sự kiện chạm vào nút đánh chặn giám sát?
#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
Có cách nào để ngăn chặn những sự kiện liên lạc bị gửi đến các nút? Những gì tôi muốn cuối cùng làm là làm cho một lớp con UIView sẽ nói cho bộ điều khiển xem của nó (hoặc đại biểu, tùy theo điều kiện) khi nó phát hiện một swipe để nó có thể "đẩy" bộ điều khiển xem tiếp theo vào ngăn xếp (tương tự như màn hình chính iPhone). Tôi đã nhận ra đây là bước đầu tiên, nhưng tôi mở lời đề xuất nếu tôi tiếp cận điều này không chính xác.
bạn không có nghĩa là trả lại [superview hitTest: point withEvent: event]; –
'super' là đúng bởi vì bạn sẽ muốn gọi các lớp cha mẹ lớp phương pháp,' superview' sẽ bỏ qua này. – keegan3d