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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:45:13+00:00 2026-05-13T18:45:13+00:00

So, I have a UIView subclass called MovableBlock . It overrides touchesBegan , touchesMoved

  • 0

So, I have a UIView subclass called MovableBlock. It overrides touchesBegan, touchesMoved, touchesEnded and touchesCancelled. The moving about part works just fine.

When a MovableBlock is moved to the left side of the screen, it’s 130px wide. When it’s moved to the right side of the screen, it’s 80px wide. I’d like to animate the transition in size, so that as the user is dragging the view around, the MovableBlock smoothy adjusts its size.

Right now, I have this:

// Handles the start of a touch
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGPoint pt = [[touches anyObject] locationInView:self];
    startLocation = pt;
}

// Handles the continuation of a touch.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{  
    CGPoint svpt = [[touches anyObject] locationInView:self.superview];
    CGPoint pt = [[touches anyObject] locationInView:self];
    if (svpt.x < 130) {
        [self setColumn:0];
    }
    else {
        [self setColumn:1];
    }

    CGRect frame = [self frame];
    frame.origin.x += pt.x - startLocation.x;
    frame.origin.y += pt.y - startLocation.y;

    [self setFrame: frame];
}

-(void)setColumn: (NSInteger)newColumn {
    column = newColumn;
    if (column != newColumn) {
        [UIView beginAnimations:@"Resize Block" context:nil];
        [UIView setAnimationDuration:0.2];

        if (column == 0) {
            [self setBounds: CGRectMake(self.bounds.origin.x, self.bounds.origin.y, 130, self.bounds.size.height)];
        }
        else {
            [self setBounds: CGRectMake(self.bounds.origin.x, self.bounds.origin.y, 80, self.bounds.size.height)];
        }
        [UIView commitAnimations];
    }
}

startPosition and column are both members of the class.

While dragging the MovableBlock around, it doesn’t resize (or animate). I can’t seem to find any reason why it shouldn’t work, though I also can’t find examples of doing this, so maybe there’s some subtle trick that I’m missing.

There is another animation in the touchesEnded method that works just fine, so I know that the animation part of things is working, just not in touchesMoved.

Thanks for any help!

  • 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-13T18:45:13+00:00Added an answer on May 13, 2026 at 6:45 pm

    I seem to have figured it out. Using setBounds in the setColumn method didn’t seem to get noticed by the susequent call of frame = [self frame]. Moving the frame declaration to the top, above the calls to setColumn and restructuring how to determine the width of the current column solved things.

    Also, don’t mix frames and bounds. You’ll just confuse your headmeats. 🙂

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

Sidebar

Related Questions

I have a UIView subclass that overrides UIResponder's touchesMoved: message. I've noticed that when
I have a UIView subclass that draws itself when -drawRect: is called. It only
Im have a subclass of UIView, called PinView, which contains an image. Basically PinView
I have a subclass of UIView called SlideOut. I want to capture the IB
I have subclass of UIView, MyView. I also have a category on UIView called
I have a Class called Boards and it is a subclass of UIView ,
I have a UIView subclass called ToolbarView that sort of acts like a floating
I have a UIView subclass called Card that I move around on my board
I have a class called ToolbarView which is a subclass of UIView and basically
I have a class called ToolbarView which is a subclass of UIView and basically

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.