Coso2D中UIWebView的奇怪行为

时间:2013-01-24 07:22:27

标签: uiview uiwebview cocos2d-iphone

以下一段代码导致我的游戏崩溃..如果我发表评论,我完全没有问题......我真的看不出任何错误......我首先想到它可能是由记忆引起的问题,但在我的dealloc方法中,我发布了视图和webview ..我做错了什么?

view = [[UIView alloc] initWithFrame:CGRectMake(0, self.boundingBox.size.width, self.boundingBox.size.width, self.boundingBox.size.height)];

         NSString *urlAddress=@"http://www.google.com";

         NSURL *url = [NSURL URLWithString:urlAddress];
         NSURLRequest *reqObject=[NSURLRequest requestWithURL:url];
         webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.boundingBox.size.width, self.boundingBox.size.height )];
         webView.delegate = self;
         [webView loadRequest:reqObject];
         [view addSubview:webView];

        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button setImage:[UIImage imageNamed:@"ok-button"] forState:UIControlStateNormal];

        [button addTarget:self
                   action:@selector(web)
         forControlEvents:UIControlEventTouchDown];
        [button setTitle:@"Show View" forState:UIControlStateNormal];
        button.frame = CGRectMake(self.boundingBox.size.width - 40, 10, 30, 30.0);
        [view addSubview:button];

         [[[CCDirector sharedDirector] openGLView] addSubview:view];

1 个答案:

答案 0 :(得分:0)

我在cocos2d游戏中使用了UIWebview并且运行良好。我的代码是:

        AppController *app =  (AppController*)[[UIApplication sharedApplication] delegate];

        self.infoWebView = [[UIWebView alloc] initWithFrame:webFrame];
        self.infoWebView.backgroundColor = [UIColor whiteColor];

        self.infoWebView.scalesPageToFit = YES;
        self.infoWebView.layer.cornerRadius = 15;
        self.infoWebView.layer.borderWidth = 5;
        self.infoWebView.layer.borderColor = [[UIColor whiteColor] CGColor];

        self.infoWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
        self.infoWebView.delegate = self;
        self.infoWebView.clipsToBounds = YES;

        [app.navController.view addSubview:self.infoWebView];

        [self.infoWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:GOODIES_HTML]]];