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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:01:41+00:00 2026-05-28T13:01:41+00:00

I have a simple custom UIView (a rectangle) that is implemented with drawRect. The

  • 0

I have a simple custom UIView (a rectangle) that is implemented with drawRect.

The view is drawn from two values; currentValue and maxValue

From drawRect:

The height of the rect represents how much currentValue is of maxValue:

if(currentValue > maxValue)
    currentValue = maxValue;

float scale = currentValue/maxValue;

//Draw the rect
CGContextBeginPath(context);
CGContextMoveToPoint(context, self.bounds.origin.x, self.bounds.size.height);
CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height);
CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height-(self.bounds.size.height*scale));
CGContextAddLineToPoint(context, self.bounds.origin.x, self.bounds.size.height-(self.bounds.size.height*scale));
CGContextClosePath(context);

CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextFillPath(context);
CGContextStrokePath(context);

I’ve setup a ViewController with a UISlider that changes the currentValue and each time it’s changed setNeedsDisplay gets called. This part works just fine. The rect changes height when the slider is used, exactly as planned.

My question is.. I would like this transition between heights to be animated. What’s the best way to do it?

Thanks

  • 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-28T13:01:41+00:00Added an answer on May 28, 2026 at 1:01 pm

    Instead of having UIView with custom drawing your can add CAShapeLayer object to your view’s layer. CAShapeLayer class allows to specify path to draw and draw attributes – and also changes for those properties are easily animatable.

    If your view is just a rect filled with solid color as in question your second option is either adjust view’s frame or set appropriate affine transform to get required heights – both those properties are also easily animatable using animation methods in UIView class.

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

Sidebar

Related Questions

I have a simple custom view that is connected via outlet to a NIB.
I currently have a simple iPhone app that loads a custom subclass of UIView.
I have a simple (view-based) application. I want on tapping on custom UIView my
I have two simple custom controls derived from standard WPF controls. I.e. internal class
I have a simple custom web part with three drop downs that reads from
i'm missing something fundamental here. i have a very simple custom class that draws
I have a simple C++ DLL that implements a few custom actions for a
Suppose I have a simple XHTML document that uses a custom namespace for attributes:
I have the following simple custom control that I have defined for a Windows
I have a simple custom user control that uses jqGrid. the control is as

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.