如何在iphone应用程序中集成自动收报机

时间:2023-01-19 16:58:47

i want to run my view based window application with ticker.i have code for ticker but it is in cocoa.. so how can i integrate cocoa application in my project.?

我想运行我的基于视图的窗口应用程序与ticker.i有代码为ticker但它是在可可..所以我怎样才能在我的项目中集成cocoa应用程序。

this is TickerView.h file

这是TickerView.h文件

#import <Cocoa/Cocoa.h>


@interface TickerView : NSTextView {
 @private
  NSTimer     *mTimer;
  double      mOffset;
}
- (NSString *)stringValue;
- (void)setStringValue:(NSString *)stringValue;

- (void)appendString:(NSString *)s;

- (IBAction)startAnimation:(id)sender;
- (IBAction)stopAnimation:(id)sender;

@end

This is TickerView.m file

这是TickerView.m文件

#import "TickerView.h"


@implementation TickerView

- (id)initWithFrame:(NSRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    [self setEditable:NO];
    NSTextContainer *container = [self textContainer];
    [container setWidthTracksTextView:NO];
    [container setContainerSize:NSMakeSize(99999., frame.size.height)];
  }
  return self;
}

- (void)dealloc {
  [self stopAnimation:self];
  [super dealloc];
}

- (void)drawRect:(NSRect)rect {
  [super drawRect:rect];
}

- (NSString *)stringValue {
  return [[self textStorage] string];
}

- (NSDictionary *)standardAttributes {
  return [NSDictionary dictionaryWithObjectsAndKeys: 
    [NSFont fontWithName:@"Helvetica" size:([self frame].size.height * 0.8)], NSFontAttributeName,
    [NSColor redColor], NSForegroundColorAttributeName,
    nil];
}

- (void)setStringValue:(NSString *)s {
  NSRange fullRange = NSMakeRange(0, [[self textStorage] length]);
  NSAttributedString *sa = [[[NSAttributedString alloc]initWithString:s attributes:[self standardAttributes]] autorelease];
  [[self textStorage] replaceCharactersInRange:fullRange withAttributedString:sa];
}

- (void)appendString:(NSString *)s {
  NSRange endRange = NSMakeRange([[self textStorage] length], 0);
  NSAttributedString *sa = [[[NSAttributedString alloc]initWithString:s attributes:[self standardAttributes]] autorelease];
  [[self textStorage] replaceCharactersInRange:endRange withAttributedString:sa];
}


- (IBAction)startAnimation:(id)sender {
  if (nil == mTimer) {
    mTimer = [NSTimer scheduledTimerWithTimeInterval:1./60. target:self selector:@selector(step:) userInfo:nil repeats:YES];
  }
}


- (IBAction)stopAnimation:(id)sender {
  if (mTimer) {
    [mTimer invalidate];
    [mTimer release];
    mTimer = nil;
  }
}

- (void)step:(NSTimer *)timer {
  mOffset -= 2; // pixels per tick
  [self setTextContainerInset:NSMakeSize(mOffset, 0)];
  [self setNeedsDisplay:YES];
}


@end

1 个解决方案

#1


0  

You can't just drop it in (as far as I know).

你不能把它放进去(据我所知)。

I'd do it by changing your inheritance from NSTextView to UILabel and reading the docs for that. then just work through the code bit by bit until it works ;)

我是通过将您的继承从NSTextView更改为UILabel并为此阅读文档来实现的。然后只是逐步完成代码,直到它工作;)

#1


0  

You can't just drop it in (as far as I know).

你不能把它放进去(据我所知)。

I'd do it by changing your inheritance from NSTextView to UILabel and reading the docs for that. then just work through the code bit by bit until it works ;)

我是通过将您的继承从NSTextView更改为UILabel并为此阅读文档来实现的。然后只是逐步完成代码,直到它工作;)