菜鸟教程小白 发表于 2022-12-11 18:21:06

ios - UiWebView 委托(delegate)方法没有被调用


                                            <p><p>我正在尝试在 webView 中播放 youtube 嵌入视频,当我没有设置委托(delegate)时它会播放,如果我设置委托(delegate)视频不加载并且委托(delegate)方法也不会被调用。这是我的代码:</p>

<p>.m 类</p>

<pre><code>#import &#34;EmbeddedVideoVC.h&#34;

@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 {
    ;
    self.view.transform = CGAffineTransformMakeRotation(M_PI/2);      
}

-(void)viewDidAppear:(BOOL)animated{
    ;
    CGRect bounds = [ bounds];
    if (.applicationFrame.size.height &lt; 568) {
      bounds = CGRectMake(0, 0, 480, 320);
    }
    _videoWebView = [ initWithFrame:CGRectMake(0, 0,bounds.size.height, bounds.size.width)];
    ;
    ;

    ;

    hud = ;
    hud.color = ;
    hud.activityIndicatorColor = ;

    UITapGestureRecognizer *tap = [ initWithTarget:self action:@selector(didTapMethod)];
    ; // Set your own number here
    ; // Add the &lt;UIGestureRecognizerDelegate&gt; protocol
    ;
    _videoWebView.delegate= self;
    ;
    ;

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

- (void)webViewDidStartLoad:(UIWebView *)webView{
    ;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
   ;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
   ;
}
- (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
</code></pre>

<p>.h 类</p>

<pre><code>#import &#34;MusicParentVC.h&#34;

@interface EmbeddedVideoVC : MusicParentVC &lt;UIGestureRecognizerDelegate, UIWebViewDelegate&gt;

@property (strong, nonatomic)NSString *embeddedCode;
@property (nonatomic, strong) UIWebView *videoWebView;
@end
</code></pre>

<p>任何人都可以告诉我问题是什么以及为什么 webViewDidFinishLoad: 和其他委托(delegate)方法没有被调用,甚至嵌入的代码没有在 webview 中加载? </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>只需将你的 <code>UIWebView</code> 相关代码放在 <code>viewDidAppear:</code> 方法中即可。</p>

<p>引用:<a href="https://stackoverflow.com/a/27647327/2284065" rel="noreferrer noopener nofollow">https://stackoverflow.com/a/27647327/2284065</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UiWebView 委托(delegate)方法没有被调用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/41219916/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/41219916/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UiWebView 委托(delegate)方法没有被调用