Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:26:08+00:00 2026-06-08T06:26:08+00:00

A new day, a new question! I have been working on an app that

  • 0

A new day, a new question!

I have been working on an app that requires I show a circle where the users finger(s) is(are) when they are touching the screen.

I have followed a tutorial I found on subclassing UIWindow, and my comment explains how to pass on those touches if you are using Storyboards and ARC.

I am using the following code (which is based on this tutorial) to make a touch indicator to display:

#pragma mark - Touch Events
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    NSArray *subviews = [self.webView subviews];
    for (UIView *view in subviews) 
    {
        // Check if view is scrollview
        if ([view isKindOfClass:[UserTouchImageView class]])
        {
            [view removeFromSuperview];
        }
    }

    // Enumerate over all the touches and draw a red dot on the screen where the touches were
    [touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
        // Get a single touch and it's location
        UITouch *touch = obj;
        CGPoint touchPoint = [touch locationInView:self.webView]; 

        // Add touch indicator
        UserTouchImageView *touchView = [[UserTouchImageView alloc] initWithFrame:CGRectMake(touchPoint.x -15, touchPoint.y -15, 30, 30)];
        [self.webView addSubview:touchView];
    }];
    NSLog(@"Touches began");
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
    NSArray *subviews = [self.webView subviews];
    for (UIView *view in subviews) 
    {
        // Check if view is scrollview
        if ([view isKindOfClass:[UserTouchImageView class]])
        {
            [view removeFromSuperview];
        }
    }

    // Enumerate over all the touches and draw a red dot on the screen where the touches were
    [touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
        // Get a single touch and it's location
        UITouch *touch = obj;
        CGPoint touchPoint = [touch locationInView:self.webView]; 

        // Draw a red circle where the touch occurred
        UserTouchImageView *touchView = [[UserTouchImageView alloc] initWithFrame:CGRectMake(touchPoint.x -15, touchPoint.y -15, 30, 30)];
        [self.webView addSubview:touchView];
    }];
    NSLog(@"Touches moved");
}
- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
    NSArray *subviews = [self.webView subviews];
    for (UIView *view in subviews) 
    {
        // Check if view is scrollview
        if ([view isKindOfClass:[UserTouchImageView class]])
        {
            [UIView animateWithDuration:0.5f 
                             animations:^{
                                 view.alpha = 0.0;
                             }
                             completion:^(BOOL finished) {
                                 [view removeFromSuperview];
                             }];
        }
    }
    NSLog(@"Touches ended");
}
- (void) touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
    NSArray *subviews = [self.webView subviews];
    for (UIView *view in subviews) 
    {
        // Check if view is scrollview
        if ([view isKindOfClass:[UserTouchImageView class]])
        {
            [view removeFromSuperview];
        }
    }
    NSLog(@"Touches cancelled");
}

UserTouchImageView is a subclass of UIImageView, with the change to the default being:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.image = [UIImage imageNamed:@"greyCircle.png"];
        self.alpha = 0.5f;
    }
    return self;
}

I’ve tested this code without a UIWebview (replacing the self.webView with self.view), and it works fine, drawing the circle where I click and drag, then fading out when I release the button.

I have also succeeded in instantiating the UserTouchImageView and adding it to the webView from the viewDidLoad method of the viewController.

As soon as I put the UIWebview in with the code above, the same line ([self.webView addSubview:touchView];) doesn’t work. I still get the NSLog messages to the console, but the subview doesn’t get visibly added.

Can anyone help me figure out why this doesn’t appear? Is there any other code I need to be aware of, or any reason why I cannot do this?

Many thanks!

EDIT

I have uploaded my source so far here (MediaFire)

EDIT 2

I’ve added two methods as below:

-(void)listWebViewSubViews
{
    NSLog(@"BEGIN LISTING SUBVIEWS");
    for (UIView *view in [self.webView subviews]) {
        NSLog(@"Subview: %@", view.description);
    }
    NSLog(@"END LISTING SUBVIEWS");
}
-(void)view:(UIView *)view addTouchIndicatorWithCentreAtPoint:(CGPoint)point
{
    NSLog(@"View: %@, x: %f, y: %f", view.description, point.x, point.y);

    // Add touch indicator
    UserTouchImageView *touchView = [[UserTouchImageView alloc] initWithFrame:CGRectMake(point.x -15, point.y -15, 30, 30)];

    [view addSubview:touchView];


}

These are called from two buttons outside the UIWebView, and from within the touchesbegan method:

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    NSArray *subviews = [self.webView subviews];
    for (UIView *view in subviews) 
    {
        if ([view isKindOfClass:[UserTouchImageView class]])
        {
            [view removeFromSuperview];
        }
    }

    [touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
        UITouch *touch = obj;
        CGPoint touchPoint = [touch locationInView:self.webView]; 

        [self view:self.webView addTouchIndicatorWithCentreAtPoint:touchPoint];

        [self listWebViewSubViews];
    }];
    NSLog(@"Touches began");
}

The logging seems to indicate that the webview referenced by self.webView WITHIN the touches began method is an entirely seperate instance than the one when referenced from the two buttons. I can add multiple subviews via the button, and then list them, and they all show up in the logging, yet when I click to touch on the simulator, none of these extra subviews get listed.

Does anyone know of any special functionality in a UIWebView to have a duplicate instance on touch events?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:26:09+00:00Added an answer on June 8, 2026 at 6:26 am

    Problem solved:

    Unfortunately this was caused by somethign entirely different, so thank you everyone for the help you’ve given.

    The problem for this arose from my attempt to fix the code to run with storyboards. I had tried to access the view controller from the storyboard, and add that as the view to receive touch events as a priority (see the tutorial I linked to, and my comment, which I have also responded to). Where as I should have been using self.window.rootViewController.

    My updated comment is here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an app that stores the location of the places you have been
I've been trying all day with no luck to regex replace the new line
G'day, OK, I have now rewritten this question totally: I am trying to import
I've been working on this for about a day and a half now, and
I have been working with Qt and Visual Studios 2008 for a while now.
So, the noobie question of the day... I have an XML file with the
I have been writing a WP7 app and part of the functionality involves the
I know this question has been asked several times an I spent all day
This is my first question here. I have been searching Stack Overflow and other
I have been pulling my hair out on this one all day, and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.