如何在我的应用程序中实现代码在iphone
答
的“北京时间”假设你的意思是水平滚动的文字:
一个股票基本上是由具有其x坐标连续改变移动文本字符串。检查如何显示在标签上这个简单的教程:
http://knol.google.com/k/iphone-sdk-helloworld
后来的后来,你可以通过使用一个NSTimer调用更新标签X坐标连续的方法制作动画。
+0
否 - 使用UIView类来控制动画。这些都在Apple文档中。 – SK9 2010-12-07 07:06:08
答
您需要做的一切都在SDK中,根本不需要自定义。我没有检查这一点,但你可以尝试以下方法:
#import <UIKit/UIKit.h>
@interface TickerScrollView : UIScrollView {
UILabel *textLabel;
}
- (void)displayText:(NSString *)string;
- (void)clearTicker;
@property (nonatomic, retain, readwrite) UILabel *textLabel;
@end
////
#import "TickerScrollView.h"
@interface TickerScrollView()
- (void)initialiseTextLabel;
- (void)clearTicker;
- (void)beginAnimation;
@end
@implementation TickerScrollView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
[self setFrame: frame];
[self setBounces: NO];
[self setUserInteractionEnabled:NO];
[self setShowsVerticalScrollIndicator:NO];
[self setShowsHorizontalScrollIndicator:NO];
[self initialiseTextLabel];
}
return self;
}
- (void)initialiseTextLabel {
textLabel = [[[UILabel alloc] initWithFrame:self.bounds] autorelease];
[textLabel setTextAlignment:UITextAlignmentLeft];
[textLabel setNumberOfLines:1];
[textLabel sizeToFit];
[self addSubview:textLabel];
[self sendSubviewToBack:textLabel];
[self setScrollEnabled:YES];
}
- (void)displayText:(NSString *)string {
[self clearTicker];
[textLabel setText:string];
[textLabel sizeToFit];
[self setContentSize:textLabel.frame.size];
[self beginAnimation];
}
- (void)clearTicker {
[textLabel setText:@""];
[textLabel sizeToFit];
CGPoint origin = CGPointMake(0, 0);
[self setContentOffset:origin];
}
- (void)beginAnimation {
CGFloat text_width = textLabel.frame.size.width;
CGFloat display_width = self.frame.size.width;
if (text_width > display_width) {
CGPoint origin = CGPointMake(0, 0);
[self setContentOffset:origin];
CGPoint terminal_origin = CGPointMake(textLabel.frame.size.width - self.frame.size.width, textLabel.frame.origin.y);
float duration = (text_width - display_width)/50;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelay:1.0];
[UIView setAnimationDuration:duration];
[self setContentOffset:terminal_origin];
[UIView commitAnimations];
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (void)dealloc {
[textLabel release];
[super dealloc];
}
@synthesize textLabel;
@end
您可能需要确定__A ticker__多一点对我们帮助你;) – deanWombourne 2010-07-02 12:15:52
谁投票决定关闭这个问题应该由现在已经学会这是你要求海报澄清的那种问题,而不是你过于模糊的那种问题。 – 2010-07-02 14:25:15
可能的重复[有没有人有一个很好的方法来滚动文字到一边,就像在iPhone应用程序中的笔尖上的标签上的股票报价?](http://stackoverflow.com/questions/900425/does-任何人都有一个很好的方式滚动文本关闭到一边就像一个股票股票代码我) – 2010-07-02 14:32:52