• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Subject: Re: Smooth resizing of a text field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Subject: Re: Smooth resizing of a text field


  • Subject: Subject: Re: Smooth resizing of a text field
  • From: Duncan Champney <email@hidden>
  • Date: Thu, 21 Jul 2011 07:26:56 -0400

On 20 Jul 2011, at 2:30 PM, Gabriel Roth wrote:


> My application displays a non-editable text string in an NSTextField. When
> the user adjusts a slider, the entire window and all its subviews—including
> this text field—should resize smoothly.
>
> My first thought was to bind the font size of the text field to a property
> and have that property set to a fixed ratio of the window's size, resetting
> it whenever the window size changes. But when I implement this, the text
> jiggles around as it's resized.
>
> My next thought was to convert the text field into an image (at some large
> font size) and then scale the image up and down as the slider moves. But I
> can't figure out how to create an image from a text field (or otherwise
> generate an image of a string of text in a given font).
>
> Any thoughts on what avenue to pursue would be much appreciated.
>
> gr.


This sounds like a perfect fit for Core Animation.

Figure out which field(s) need to be resized.

Then use code like this:

myTextField.wantsLayer = TRUE; //Set up a CA Layer for this field.
myTextField.layer.transform = CATransform3DMakeScale(1.5, 1.5); //Scale the text field to 150%

By default, it should grow/shrink from the center of it's bounding rectangle. If you want it to grow/shrink (or rotate, or whatever) from a different point, set the anchorPoint property of the layer.

If you want to change the duration of the animation from the default (0.25 sec) , or change the animation timing from the default of ease in, ease out, put the layer changes inside a CATransaction:

myTextField.wantsLayer = TRUE; //Set up a CA Layer for this field.

[CATransaction begin];
[CATransaction setAnimationDuration: 0.1];	//Change the duration to .1 seconds
[CATransaction setAnimationTimingFunction: kCAMediaTimingFunctionLinear];  //Change the timing to linear
myTextField.layer.transform = CATransform3DMakeScale(1.5, 1.5); //Scale the text field to 150%
[CATransaction commit];


Disclaimer: I don't think I've actually used CATransaction exactly as shown above. I pulled this from the documentation, and haven't tested it.

You could also set up an animator proxy to do this, or create a CABasicAnimation on the layer.


Regards,

Duncan Champney
WareTo		_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Writing global preferences file into /Library/Preferences (OS X Lion)
  • Next by Date: iTunes 10.4 visualizers
  • Previous by thread: iTunes 10.4 plugin API
  • Next by thread: iTunes 10.4 visualizers
  • Index(es):
    • Date
    • Thread