0

2 개의 뷰 컨트롤러, firstviewcontroller 및 MyOverlayView에 대해 4 개의 파일. MyOverlayView는 touch를 수신하고 firstviewcontroller가 수신해야하는 알림을 보냅니다. 인스턴트 메신저 overlayview 터치 이벤트를 받고 있지만 firstviewcontroller에서 알림을받지 못했습니다. 어떤 아이디어?NSNotification 터치 오버레이

FVC 헤더

#import <UIKit/UIKit.h> 
#import <MediaPlayer/MediaPlayer.h> 
#import "MyOverlayView.h" 

extern NSString *const OverlayViewTouchNotification; 

@interface FirstViewController : UIViewController { 
    MPMoviePlayerViewController *mvc; 
    MyOverlayView *overlayView; 
    NSArray *keyArray; 
    NSMutableDictionary *urlDic; 
} 

@property (nonatomic, retain) MPMoviePlayerViewController *mvc; 
@property (nonatomic, retain) IBOutlet MyOverlayView *overlayView; 
@property (nonatomic, retain) NSArray *keyArray; 
@property (nonatomic, retain) NSMutableDictionary *urlDic; 

-(void)playMovieAtURL:(NSDictionary *)dic:(NSArray *)array:(int) rand; 
-(void)overlayViewTouches:(NSNotification *)notification; 
-(void)loadArray; 
-(void)reset; 
@end 

FVC-구현

#import "FirstViewController.h" 
#import "SMWebRequest.h" 

NSString * const OverlayViewTouchNotification = @"overlayViewTouch"; 

@implementation FirstViewController 
@synthesize mvc; 
@synthesize overlayView; 
@synthesize keyArray, urlDic; 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 

-(void)viewDidAppear:(BOOL)animated 
{ 
    [self loadArray]; 
    if (!overlayView) { 
     overlayView = [[MyOverlayView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    } 
    NSArray *windows = [[UIApplication sharedApplication] windows]; 
    if ([windows count] >= 1) 
    { 
     // Locate the movie player window 
     UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow]; 
     // Add our overlay view to the movie player's subviews so it is 
     // displayed above it. 
     [moviePlayerWindow addSubview:self.overlayView]; 
    } 

    //[self.parentViewController.view addSubview:overlayView]; 
} 

-(void)loadArray{ 
    if (!urlDic) { 
     NSMutableDictionary *tempDic = [NSMutableDictionary new]; 
     [tempDic setObject:@"mp4" forKey:@"euromount_high_res"]; 

     urlDic = [[NSDictionary alloc] initWithDictionary:tempDic]; 
    } 

    if (!keyArray) { 
     NSArray *tempArray = [urlDic allKeys]; 
     keyArray = [[NSArray alloc] initWithArray:tempArray]; 
    } 
    //Random choice 
    int point = rand() % ([keyArray count]); 
    //Call play movie 
    [self playMovieAtURL :urlDic :keyArray :point]; 
} 

-(void)playMovieAtURL:(NSDictionary *)dic:(NSArray *)array:(int)rand 
{ 
    NSString *key = [array objectAtIndex:rand]; 
    NSString *path = [[NSBundle mainBundle] pathForResource:key ofType:[dic valueForKey:key]]; 


    if (mvc == nil) { mvc = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; } 

    mvc.moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
    mvc.moviePlayer.shouldAutoplay = TRUE; 
    mvc.moviePlayer.controlStyle = MPMovieControlStyleNone; 

    // Register for the playback finished notification. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(myMovieFinishedCallback:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:nil]; 

    [self presentModalViewController:mvc animated:YES]; 

    // Movie playback is asynchronous, so this method returns immediately. 
    [mvc.moviePlayer play]; 
} 

// When the movie is done,release the controller. 
-(void)myMovieFinishedCallback:(NSNotification*)aNotification 
{ 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:nil]; 
    //for (UIView *view in self.view.subviews) { 
    // [view removeFromSuperview]; 
    //} 
    mvc = nil; 
    [self loadArray]; 
} 

// Touches in the overlay view (not in the overlay button) 
// post the "overlayViewTouch" notification and will send 
// the overlayViewTouches: message 
- (void)overlayViewTouches:(NSNotification *)notification 
{ 
    NSLog(@"screen touched"); 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return YES; 
} 


- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc. that aren't in use. 
} 


- (void)viewDidUnload 
{ 
    mvc = nil; 
    keyArray = nil; 
    urlDic = nil; 
    [super viewDidUnload]; 
} 

-(void)reset{ 
    for (UIView *view in self.view.subviews) { 
     [view removeFromSuperview]; 
    } 
    mvc = nil; 
    keyArray = nil; 
    urlDic = nil; 
    [self loadArray]; 
} 

- (void)dealloc 
{ 
    [super dealloc]; 
} 

@end 

MyOverlayView 헤더

#import <UIKit/UIKit.h> 


@interface MyOverlayView : UIView { 
} 

- (void)awakeFromNib; 
- (void)dealloc; 
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 

@end 

MyOverlayView-구현

#import "MyOverlayView.h" 
#import "FirstViewController.h" 

@implementation MyOverlayView 

// MPMoviePlayerController will play movies full-screen in 
// landscape mode, so we must rotate MyOverlayView 90 degrees and 
// translate it to the center of the screen so when it draws 
// on top of the playing movie it will display in landscape 
// mode to match the movie player orientation. 
// 
- (void)awakeFromNib 
{ 
    CGAffineTransform transform = self.transform; 

    // Rotate the view 90 degrees. 
    transform = CGAffineTransformRotate(transform, (M_PI/2.0)); 

    UIScreen *screen = [UIScreen mainScreen]; 
    // Translate the view to the center of the screen 
    transform = CGAffineTransformTranslate(transform, 
     ((screen.bounds.size.height) - (self.bounds.size.height))/2, 
     0); 
    self.transform = transform; 

    CGRect newFrame = self.frame; 
    newFrame.origin.x = 190; 
    self.frame = newFrame; 
} 

- (void)dealloc { 
    [super dealloc]; 
} 

// Handle any touches to the overlay view 
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch* touch = [touches anyObject]; 
    if (touch.phase == UITouchPhaseBegan) 
    { 
     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
     [nc postNotificationName:OverlayViewTouchNotification object:nil]; 
    }  
} 


@end 

****편집 답변* ** * *** 내가 신고를위한 관찰자를 추가 않네 . 그것 모두는 분류했다.

답변

0

신고 대상자를 추가하지 않았습니다. 알았습니다. 정렬되었습니다.