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 8468375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:54:48+00:00 2026-06-10T15:54:48+00:00

I have just started working on a project and I already have a few

  • 0

I have just started working on a project and I already have a few problems and errors. I was wondering if you guys could help me figure out where the bug is.

Quick overview: I have two files: (ViewController.m and Scroller.m). In the ViewController I have some code under ViewDidLoad (which I’ll show in a second), I also have a function (addImagesToView) that does what it says, and some touchesBegan,moved and ended for intractability.

In the Scroller I decided to rewrite some of the “-(void)touches” functions implementations.

The problem I have: is that the buttons (coming from the addImagesToView function) get stuck on highlighted. I performed some tests with an NSLog to see which “touches” working and which don’t. “touchesMoved” doesn’t work properly. If the user drags downward, the log stops after about 3 or 4 lines of text. I think that it interferes with the scroll somehow.

This is the content of ViewController.m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bgPNG.png"]];

    imageView.frame = CGRectMake(0, 0, 320, 480);
    [self.view addSubview:imageView];

    //UIColor *background = [[UIColor alloc]initWithPatternImage:imageView.image];
    //self.view.backgroundColor = background;

    CGRect fullScreen = [[UIScreen mainScreen] applicationFrame];

    scroll = [[Scroller alloc] initWithFrame:fullScreen];
    scroll.contentSize = CGSizeMake(320, 2730);

    scroll.delaysContentTouches = NO;
    //scroll.canCancelContentTouches = NO;
    scroll.scrollEnabled  = YES;

    [self.view addSubview:scroll];

    buttons = [[NSMutableArray alloc]init];

    [self addImagesToView];



}

-(void) addImagesToView{




    CGFloat yCoordinate = 35;

    for (int i=1; i<=18; i++) {

        UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"picture%d.png",i]]highlightedImage:[UIImage imageNamed:[NSString stringWithFormat:@"picture%dHG.png",i]]];

        CGRect position = CGRectMake(105, yCoordinate, IMAGE_SIZE, IMAGE_SIZE);
        image.frame = position;

        [scroll addSubview:image];

        image.userInteractionEnabled = YES;
        image.tag = i;

        [buttons addObject:image];
        yCoordinate += 150;


    }
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Get any touch
    UITouch *t = [touches anyObject];


    if ([t.view class] == [UIImageView class])
    {

        // Get the tappedImageView
        UIImageView *tappedImageView = (UIImageView*) t.view;
        tappedImageView.highlighted = YES;
    }
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *t = [touches anyObject];
    if ([t.view class] == [UIImageView class])
    {

        // Get the tappedImageView
        UIImageView *tappedImageView = (UIImageView*) t.view;
        tappedImageView.highlighted = NO;
    }

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources th at can be recreated.
}

@end

and this is the Scroller.m

#import "Scroller.h"

@implementation Scroller

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (!self.dragging)
        [self.nextResponder touchesBegan: touches withEvent:event];
    else
        [super touchesBegan: touches withEvent: event];
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *t = [touches anyObject];
    if ([t.view class] == [UIImageView class])
    {

        // Get the tappedImageView
        UIImageView *tappedImageView = (UIImageView*) t.view;
        tappedImageView.highlighted = NO;
    }

}


-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (!self.dragging)
        [self.nextResponder touchesEnded: touches withEvent:event];
    else
        [super touchesEnded: touches withEvent: event];        // Get the tappedImageView

}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect
 {
 // Drawing code
 }
 */

@end

I have also tried to implement all the touches in the ViewController, but I don’t know how to make it read from the scroll (please notice the diff. between SCROLL and SCROLLER).

As you can tell I’ve tried to order them like this: view -> backGroundImage ->scroller ->addImagesToView(function), so that the images that come out from [I]addImagesToView[/I] are on top of the scroll. That’s my desired hierarchy.

Thank you very much.

  • 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-10T15:54:49+00:00Added an answer on June 10, 2026 at 3:54 pm

    You don’t have to write your own touch handling routines for button presses. Instead of using UIImageViews, just create UIButtons instead and hook into their UIControlEventTouchUpInside event.

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

Sidebar

Related Questions

I have just started working on an open source project. The project is hosted
I have just started working on a struts2 project. I have seen the power
I have just started my project but have run into problems which is preventing
I have just started working with a new Coldfusion project, well the project is
I am currently working on a C# project. I have just started needing to
I have just started working on a project and I am using zend framework
I have just started working on an MVC project and things are going ok
I have just started leaning and working on xquery with java. I have a
I just started working with Android and I have a problem with my map.
I've just started working with Propel and I love it, but I have a

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.