我对苹果提供的MoviePlayer示例代码有疑问。
我不明白overlayViewTouch 通知是如何工作的。当我触摸视图(不是按钮)时,不会发送我添加到其中的 NSlog 消息。
// post the "overlayViewTouch" notification and will send
// the overlayViewTouches: message
- (void)overlayViewTouches:(NSNotification *)notification
{
NSLog(@"overlay view touched");
// Handle touches to the overlay view (MyOverlayView) here...
}
但是,如果我将它放在“MyOverlayView.m”中的 -(void)touchesBegan 中,我可以获得 NSlog 通知。这让我认为它正在识别触摸但不发送通知。
// Handle any touches to the overlay view
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
if (touch.phase == UITouchPhaseBegan)
{
NSLog(@"overlay touched(from touchesBegan")
// IMPORTANT:
// Touches to the overlay view are being handled using
// two different techniques as described here:
//
// 1. Touches to the overlay view (not in the button)
//
// On touches to the view we will post a notification
// "overlayViewTouch". MyMovieViewController is registered
// as an observer for this notification, and the
// overlayViewTouches: method in MyMovieViewController
// will be called.
//
// 2. Touches to the button
//
// Touches to the button in this same view will
// trigger the MyMovieViewController overlayViewButtonPress:
// action method instead.
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:OverlayViewTouchNotification object:nil];
}
}
谁能阐明我错过了什么或做错了什么?
谢谢你。