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

  • Home
  • SEARCH
  • 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 3421646
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:07:35+00:00 2026-05-18T06:07:35+00:00

I am trying to figure out how I can set a button to not

  • 0

I am trying to figure out how I can set a button to not be highlighted when touchesmoved leaves the frame of the current selected button. See code below. The below code should allow any of the three buttons to be pressed individually and swipped. The problem I am having is that when the buttons a swipped eg using touchesmoved the buttons call the Actions but never set the buttons back to not be highlighted when the swipe leaves the button frame.

Thanks in advance,

Azza

- (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event {
for(UITouch *t in touches) { 

CGPoint location = [t locationInView:t.view]; 

if((CGRectContainsPoint(Button1.frame, location))  && (!Button1.isHighlighted))
{ 
    if (!Button1.isHighlighted){ 
       [Button1 setHighlighted:YES];
       [self doAction1]; 
     }else{
       [Button1 setHighlight:NO];
     }
 }

if((CGRectContainsPoint(Button2.frame, location))  && (!Button2.isHighlighted))
{ 
    if (!Button2.isHighlighted){ 
       [Button2 setHighlighted:YES];
       [self doAction2]; 
     }else{
       [Button2 setHighlight:NO];
     }
 }

if((CGRectContainsPoint(Button3.frame, location))  && (!Button3.isHighlighted))
{ 
    if (!Button3.isHighlighted){ 
       [Button3 setHighlighted:YES];
       [self doAction3]; 
     }else{
       [Button3 setHighlight:NO];
     }
 }
 }

- (void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event {
for(UITouch *t in touches) { 

CGPoint location = [t locationInView:t.view]; 

if(CGRectContainsPoint(Button1.frame, location))
{ 
    if (!Button1.isHighlighted){ 
       [Button1 setHighlighted:YES];
       [self doAction1]; 
     }
 }

if(CGRectContainsPoint(Button2.frame, location)) 
{ 
    if (!Button2.isHighlighted){ 
       [Button2 setHighlighted:YES];
       [self doAction2]; 
     }
 }

if(CGRectContainsPoint(Button3.frame, location))
{ 
    if (!Button3.isHighlighted){ 
       [Button3 setHighlighted:YES];
       [self doAction3]; 
     }
 }
 }


- (void)touchesEnded: (NSSet *)touches withEvent:(UIEvent *)event {

    for (UITouch *t in touches){
    CGPoint location = [t locationInView:self.view]; 

    if(CGRectContainsPoint(Button1.frame, location)) {    
        [Button1 setHighlighted:NO];

    } else if(CGRectContainsPoint(Button2.frame, location)) { 
           [Button2 setHighlighted:NO];

    } else if(CGRectContainsPoint(Button3.frame, location)) { 
       [Button3 setHighlighted:NO];
    }
   }
 }
  • 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-05-18T06:07:35+00:00Added an answer on May 18, 2026 at 6:07 am

    OK, I know I’ve handled this same issue before. I also see a reference to it in my own comments in the code. I’ve attached a chunk of very old code that I wrote to handle simulated buttons (similar to what you are doing). Maybe looking through this will help:

    typedef struct {
                BOOL enabled;
                BOOL isActivated;
                NSTimeInterval activatedStartTime;
                NSTimeInterval holdTime;
                CGRect frame;
                UIImageView *glowImage;
                BOOL processPending;
                SEL callWhenTouched;
                } SIM_BUTTON;
    
    
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
        {
        int fingers = [touches count];
        UITouch *touch;
        CGPoint touchPoint;
        int i, j;
    
        for (i=0; i<fingers; i++)
            {
            touch = [[touches allObjects] objectAtIndex:i];
            touchPoint = [touch locationInView:self.view];
    
    
            for ( j=0; j<SIM_BUTTON_COUNT; j++)
                {
                if ( simButton[j].enabled && CGRectContainsPoint( simButton[j].frame, touchPoint) )
                    {
                    simButton[j].isActivated=YES;
                    simButton[j].activatedStartTime = [NSDate timeIntervalSinceReferenceDate];
                    simButton[j].processPending = YES;
                    }
                }
            }
        }
    
    
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
        {
        int fingers = [touches count];
        UITouch *touch;
        CGPoint touchPoint;
        CGPoint previousTouchPoint;
        int i, j;
    
        for (i=0; i<fingers; i++)
            {
            touch = [[touches allObjects] objectAtIndex:i];
            touchPoint = [touch locationInView:self.view];
            previousTouchPoint = [touch previousLocationInView:self.view];
    
            for ( j=0; j<SIM_BUTTON_COUNT; j++)
                {
                if ( simButton[j].enabled && simButton[j].isActivated && CGRectContainsPoint( simButton[j].frame, touchPoint) && CGRectContainsPoint( simButton[j].frame, previousTouchPoint) )
                    {
                    simButton[j].isActivated=YES;
                    }
                else
                if ( simButton[j].enabled && !simButton[j].isActivated && CGRectContainsPoint( simButton[j].frame, touchPoint) && CGRectContainsPoint( simButton[j].frame, previousTouchPoint) )
                    {
                    simButton[j].activatedStartTime = [NSDate timeIntervalSinceReferenceDate];
                    simButton[j].isActivated=YES;
                    }
                else
                if ( simButton[j].enabled && simButton[j].isActivated && !CGRectContainsPoint( simButton[j].frame, touchPoint) && CGRectContainsPoint( simButton[j].frame, previousTouchPoint) )
                    {
                    simButton[j].isActivated=NO;
                    simButton[j].activatedStartTime = (NSTimeInterval)0.0;
                    }
                else
                if ( simButton[j].enabled && !simButton[j].isActivated && CGRectContainsPoint( simButton[j].frame, touchPoint) && !CGRectContainsPoint( simButton[j].frame, previousTouchPoint) )
                    {
                    simButton[j].isActivated=YES;
                    simButton[j].activatedStartTime = [NSDate timeIntervalSinceReferenceDate];
                    simButton[j].processPending = YES;
                    }
    
                //
                // If the user touched the SCAN button and then slid their finger off of the SCAN button
                //
                if ( scannerActive==YES && simButton[RIGHT_SCAN_BUTTON].isActivated==NO && CGRectContainsPoint( simButton[RIGHT_SCAN_BUTTON].frame, previousTouchPoint) )
                    {
                    phraseMode = EXTERNAL_SCAN_PHRASES;     // Default
                    }
                }
            }
        }
    
    
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
        {
        int fingers = [touches count];
        UITouch *touch;
        CGPoint touchPoint;
        CGPoint previousTouchPoint;
        int i, j;
    
        for (i=0; i<fingers; i++)
            {
            touch = [[touches allObjects] objectAtIndex:i];
            touchPoint = [touch locationInView:self.view];
            previousTouchPoint = [touch previousLocationInView:self.view];
    
            for ( j=0; j<SIM_BUTTON_COUNT; j++)
                {
                if ( simButton[j].enabled && simButton[j].isActivated && (CGRectContainsPoint( simButton[j].frame, touchPoint) || CGRectContainsPoint( simButton[j].frame, previousTouchPoint)) )
                    {
                    simButton[j].isActivated=NO;
                    simButton[j].activatedStartTime = (NSTimeInterval)0.0;
                    }
                }
            }
        }
    
    
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
        {
        [self touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event];
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out how can I update the petevents table with
I trying to figure out how I can delete from multiple tables in SQL
I'm trying to figure out how I can download a particular tag of a
I am trying to figure out how I can update my sql query dynamically.
I am trying to figure out how I can define an autocmd that influences
I'm trying to figure out if I can get what I want out of
I've been trying to figure out how I can make a query with MySQL
I'm trying to figure out how I can have a comment header automatically added
I'm trying to figure out how I can do an if statement with this
I am trying to figure out how I can get notified when the keyboard

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.