Problem of UIWebView in cocos2d. The View is not disappearing in next scene .

Discussion in 'iOS Programming' started by srikanthrongali, Jun 29, 2010.

  1. srikanthrongali macrumors newbie

    Apr 30, 2010
    hi, I am using UIWebView to display the scrolling text in a scene in cocos2d. Some times the text is appearing in the next scene also. And it is not disappeared in any next scene. When I restart the game it is again fine. I released it and removed it from superview. But the problem occurs only some times . I could not get where I am wrong in my program. Can you suggest me.

        if((self = [super init]))
    	self.isTouchEnabled  = YES;	
    //I added the button here. When we touch it takes to next scene.
    	CCMenuItem *buttonItem = [CCMenuItemImage itemFromNormalImage:@"buttonA.png" selectedImage:@"buttonB.png" target:self selector:@selector(buttonPressed:)];
    	CCMenu *buttonMenu = [CCMenu menuWithItems: buttonItem, nil] ;
    	[buttonMenu alignItemsVertically];
    	buttonMenu.position = ccp(windowSize.width/2 + 200, windowSize.height/2-60);
    	[self addChild:buttonMenu z:1];
    	self.myUIWebView = [[UIWebView alloc]initWithFrame:CGRectMake(10, 10, 250, 250)];
    	[self.myUIWebView loadData:contentData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[ NSURL URLWithString:@"" ]];
    	[self.myUIWebView setBackgroundColor:[UIColor clearColor]];
    	[self.myUIWebView setOpaque:NO];
    	self.myUIWebView.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS( 90.0f ));
    	[[[CCDirector sharedDirector] openGLView] addSubview:self.myUIWebView];
      return self;
    {	[self.myUIWebView removeFromSuperview];
    	CCScene *Scene = [CCScene node];
    	CCLayer *Layer = [ChoicesScreen node];
    	[Scene addChild: Layer];
    	[[CCFastDirector sharedDirector] replaceScene: Scene];
    	[self.myUIWebView release];
    	[super dealloc];
    Thank you.
  2. bweberapps macrumors member

    Jun 25, 2010
    I have the same exact problem with a UITextView I have in my cocos2s game. I haven't found a solution yet, but will let you know what I come across.
  3. srikanthrongali thread starter macrumors newbie

    Apr 30, 2010
    I used to get this problem when I tap the screen continuously. For this my problem solved.
    I added the line self.isTouchEnabled = NO; in touchesEnded method in the scene that is before the text displaying scene.

    In my code I have a sceneA. When I tap it I get the sceneB which have the scrolling text. So I added in sceneA's touchesEnded method the self.isTouchEnabled = NO;

    I checked my game and it is working fine till now. If I have got the same problem again I will share with you.

    Thank you.

Share This Page