0

In a long animated-moving string from right to left, I want to get actually visible substring. Is it possible to get it in an animation process?

I must keep two features of the banner:

  1. smooth moving
  2. get substring (few characters) in some point on the screen

It is long string in one line.

I use this animation:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:10.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

...

[UIView commitAnimations];

I tried with:

CGPoint currentPosition = [[self.autoScrollText.layer presentationLayer] position];

but unsuccessfully...

iPadDeveloper2011
  • 4,560
  • 1
  • 25
  • 36
escape321
  • 39
  • 7
  • You want to control the text position, relative to the banner--which is a UIView, and which is moving? – iPadDeveloper2011 Mar 13 '11 at 00:48
  • @iPadDeveloper2011 banner is UITextView which is subview of ScrollView – escape321 Mar 13 '11 at 16:23
  • @escape321. OK, so you _don't_ want to move your text, relative to the banner, you just want to change the text in the banner? like: "..."->"lo..."->"ello..."->"hello..."? – iPadDeveloper2011 Mar 14 '11 at 00:09
  • BTW a UITextView _is a_ UIScrollView, which _is a_ UIView (UITextView is a _type_ of UIScrollView which is a type of UIView). UITextView _is not_ a subview of UIScrollView, it is a _subclass_. – iPadDeveloper2011 Mar 14 '11 at 00:15
  • @escape321. Please reformulate/clarify your question. As is, it is a bad/unclear question which deserves to be voted down. – iPadDeveloper2011 Mar 14 '11 at 00:23
  • @iPadDeveloper2011 I did some changes on my question...I hope it is more clear now.. – escape321 Mar 14 '11 at 22:18
  • @escape321. No, it is still not clear. If you want a substring of an `NSString`, you should use methods like `substringFromIndex, substringToIndex`, and `substringWithRange`. The fact that it is animated/moving is irrelevant. – iPadDeveloper2011 Mar 15 '11 at 01:39
  • @iPadDeveloper2011 It is long animated-moving string from right to left, and i want to get actually visible substring.I think index and range doesn't help here... – escape321 Mar 15 '11 at 22:15
  • which property of the UITextView do you animate? I guess the frame's origin ... – Felix Mar 15 '11 at 22:47
  • @phix23 currently I use AutoScrollLabel Created by Brian Stormont on Copyright 2009 Stormy Productions....which is UITextField *label – escape321 Mar 16 '11 at 00:02
  • @phix23 this is piece of his scroll function: [UIView setAnimationDuration:label[0].frame.size.width/(float)scrollSpeed]; if (scrollDirection == AUTOSCROLL_SCROLL_LEFT){ self.contentOffset = CGPointMake(label[0].frame.size.width+LABEL_BUFFER_SPACE,0); }else{ self.contentOffset = CGPointMake(0,0); } [UIView commitAnimations]; – escape321 Mar 17 '11 at 22:51
  • @escape321 "It is long animated-moving string from right to left, and i want to get actually visible substring." This should be in your initial question. – iPadDeveloper2011 Mar 18 '11 at 06:53

2 Answers2

0

If your text is in a standard width font, like Courier, you could do this by relating the position of your UITextView, the width of your characters, and the LHS and RHS of your viewport.

iPadDeveloper2011
  • 4,560
  • 1
  • 25
  • 36
  • In the beginning was Currier, and everything was easy when I moved frame.x from left to right...I had the absolute control and any substring what I want....but font is ugly and moving frame by pixel is not smooth.So, now I have animation and Helvetica font...is any hope for my case? – escape321 Mar 20 '11 at 22:07
0

Another possibility is to use a heuristic. I guess you are doing a number (i) of different things depending on which string is "visible" when the user clicks a button. Precisely which of these things ultimately depends on the origin (x position) of your text string. Instead of working this out programatically, work it out yourself (through observation/trial and error) and select between the i different options based on the ranges of x that you determine.

iPadDeveloper2011
  • 4,560
  • 1
  • 25
  • 36
  • I guess [this SO question/answer](http://stackoverflow.com/questions/1324379/how-to-calculate-the-width-of-a-text-string-of-a-specific-font-and-font-size) may help also. – iPadDeveloper2011 Mar 24 '11 at 04:24