2016-12-19 2 views
0

위젯을 설정하지 않은 경우 webView에서 YouTube 비디오를 재생하려고합니다. 위임 비디오를로드하지 않고 위임 메서드를 호출해도 메서드가 호출되지 않습니다. 여기에 내 코드입니다 :UiWebView 대리자 메서드가 호출되지 않음

하는 .m 클래스

#import "EmbeddedVideoVC.h" 

@interface EmbeddedVideoVC(){ 
    MBProgressHUD *hud; 
} 
//@property (weak, nonatomic) IBOutlet UIWebView *webView; 
@property (weak, nonatomic) IBOutlet UIView *viewSelf; 

@property (strong, nonatomic) NSTimer *controllersTimer; 
@property (assign, nonatomic) NSInteger controllersTimeoutPeriod; 

@end 

@implementation EmbeddedVideoVC 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.view.transform = CGAffineTransformMakeRotation(M_PI/2);  
} 

-(void)viewDidAppear:(BOOL)animated{ 
    [super viewDidAppear:animated]; 
    CGRect bounds = [[UIScreen mainScreen] bounds]; 
    if ([SharedAppManager sharedInstance].applicationFrame.size.height < 568) { 
     bounds = CGRectMake(0, 0, 480, 320); 
    } 
    _videoWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0,bounds.size.height, bounds.size.width)]; 
    [_videoWebView setAllowsInlineMediaPlayback:YES]; 
    [_videoWebView setMediaPlaybackRequiresUserAction:NO]; 

    [self.viewSelf addSubview:_videoWebView]; 

    hud = [MBProgressHUD showHUDAddedTo:_videoWebView animated:YES]; 
    hud.color = [UIColor clearColor]; 
    hud.activityIndicatorColor = [UIColor whiteColor]; 

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMethod)]; 
    [tap setNumberOfTapsRequired:1]; // Set your own number here 
    [tap setDelegate:self]; // Add the <UIGestureRecognizerDelegate> protocol 
    [_videoWebView addGestureRecognizer:tap]; 
    _videoWebView.delegate= self; 
    [_videoWebView loadHTMLString:self.embeddedCode baseURL:nil]; 
    [self hideControllers]; 

} 
-(void)didTapMethod{ 
    //Showing Controls 
} 
#pragma mark - WEBVIEW DELEGATES 

- (void)webViewDidStartLoad:(UIWebView *)webView{ 
    [MBProgressHUD hideHUDForView:self.videoWebView animated:YES]; 
} 
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
{ 
    [MBProgressHUD hideHUDForView:self.videoWebView animated:YES]; 
} 
-(void)webViewDidFinishLoad:(UIWebView *)webView { 
    [MBProgressHUD hideHUDForView:self.videoWebView animated:YES]; 
} 
- (BOOL)prefersStatusBarHidden { 

    return YES; 
} 


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
    { 
     return YES; 
    } 

-(void)hideControllers { 
    [UIView animateWithDuration:0.5f animations:^{ 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     topView.hidden= YES; 
    }); 
    } completion:^(BOOL finished){ 
    }]; 
} 


-(void) showControles { 

} 

@end 

.H 클래스

#import "MusicParentVC.h" 

@interface EmbeddedVideoVC : MusicParentVC <UIGestureRecognizerDelegate, UIWebViewDelegate> 

@property (strong, nonatomic) NSString *embeddedCode; 
@property (nonatomic, strong) UIWebView *videoWebView; 
@end 

사람이 문제와 왜 webViewDidFinishLoad 무엇인지 말해 줄 수 : 다른 사람을 위임 방법은 전화 안한다 심지어 임베디드 코드가 webview에서로드되지 않습니까?

+0

"hideControllers"메서드는 어디에 있습니까? 그 코드를 붙여 넣을 수 있습니까? –

+0

- (무효) hideControllers {[UIView의 animateWithDuration : 0.5F 애니메이션^{ dispatch_async (dispatch_get_main_queue()^{ topView.hidden = YES; }); 완료 :^(BOOL 완료) { }]; } –

답변

0

1) 현재의 클래스 뷰 또는 상위 뷰 웹보기를 추가하고 있는지 확인하십시오.

2) 스토리 보드에 viewSelf를 추가하고 있습니까? 프로그래밍 방식으로 볼 수 없기 때문입니다. viewSelf에 웹보기를 추가하고 있으므로 확인하십시오.

3) hideControllers에서 일부 topView가 숨겨져 있습니다. 현재 클래스 topView가 아닌지 확인하십시오.

여기이 도움이

_videoWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)]; 
[_videoWebView setAllowsInlineMediaPlayback:YES]; 
[_videoWebView setMediaPlaybackRequiresUserAction:NO]; 


UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMethod)]; 
[tap setNumberOfTapsRequired:1]; // Set your own number here 
[tap setDelegate:self]; // Add the <UIGestureRecognizerDelegate> protocol 
[_videoWebView addGestureRecognizer:tap]; 
_videoWebView.delegate= self; 


NSURL *nsurl=[NSURL URLWithString:@"http://www.google.com"]; 
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl]; 
[_videoWebView loadRequest:nsrequest]; 
[self.view addSubview:_videoWebView]; 

희망, (대리자 메서드도 호출하는) 나를 위해 작동하는 코드입니다.

+0

@Intsab Haider, 문제가 해결 되었습니까? –

관련 문제