李程站 发表于 2013-2-4 02:27:10

IOS应用程序跑马灯效果案例

IOS应用程序跑马灯效果案例是本文要介绍的内容,内容不多,主要是以代码实现跑马灯效果的内容。先来看详细内容。最新项目中要求实现web页面中常有的跑马灯效果来显示广告内容。ios中没有提供相应的api,下面是利用NSTimer和NSLable实现的一个跑马灯效果。界面如下:
http://images.51cto.com/files/uploadimg/20110729/1005180.png
实现的代码如下:

[*]#import "AdvertisingView.h"   
[*]#import <QuartzCore/QuartzCore.h>   
[*]@implementation AdvertisingView   
[*]@synthesize myArray;   
[*]- (id)initWithFrame:(CGRect)frame {   
[*]    self = ;   
[*]    if (self) {   
[*]      ];   
[*]      if (myAdView==nil) {   
[*]            myAdView=[ initWithFrame:CGRectMake(0, 0, 188, 33)];   
[*]            ;   
[*]            if (myLable==nil) {   
[*]                myLable=[ initWithFrame:CGRectMake(0, 23, 175, 33)];   
[*]                ];   
[*]                ;   
[*]                ];   
[*]                ;   
[*]            }   
[*]            ];   
[*]            ;   
[*]      }   
[*]    }   
[*]    return self;   
[*]}   
[*]- (void)dealloc {   
[*]    [ removeObserver:self];   
[*]    if (timer!=nil&&) {   
[*]      ;   
[*]      timer=nil;   
[*]    }   
[*]    self.myArray=nil;   
[*]    ;   
[*]    myAdView=nil;   
[*]    ;   
[*]    myLable=nil;   
[*]    ;   
[*]    ;   
[*]}   
[*]-(void)addAdvertisingList   
[*]{   
[*]    //数据层   
[*]    self.myArray=[ initWithCapacity:1];   
[*]    ;   
[*]    ;   
[*]    [self.myArray addObject:@"Support for Spring Social 1.0.0.RC1, and Spring Security 3.1.0.RC2 through the Spring Android Auth module,
[*]                               which includes a SQLite datastore for persisting OAuth API connections."];   
[*]    if () {   
[*]      ;   
[*]      NSString *text=nil;   
[*]      for ( int i=0; i<; i++) {   
[*]            if (i==0) {   
[*]                text=;   
[*]            }else{   
[*]                text=];   
[*]            }   
[*]      }   
[*]      UIFont *font = ;   
[*]      CGSize size = ;   
[*]      CGRect rect=myLable.frame;   
[*]      rect.size=size;   
[*]      ;   
[*]      ;   
[*]      if (timer==nil) {   
[*]            timer=[NSTimer scheduledTimerWithTimeInterval: 0.05   
[*]                                                   target: self   
[*]                                                 selector: @selector(handleTimer:)   
[*]                                                 userInfo: nil   
[*]                                                repeats: YES];   
[*]      }   
[*]    }   
[*]}   
[*]-(void)handleTimer:(id)sender   
[*]{   
[*]    if (>0) {   
[*]      CGRect newFrame1 = myLable.frame;   
[*]      if (newFrame1.origin.y<-newFrame1.size.height) {   
[*]            newFrame1.origin.y = 23;   
[*]            ;   
[*]      }else {   
[*]            newFrame1newFrame1.origin.y =newFrame1.origin.y-0.8;   
[*]            ;   
[*]      }      
[*]    }   
[*]}   
[*]-(void)drawMainLable:(CGRect)newFrame   
[*]{   
[*]    CGRect newFrame1 = myLable.frame;   
[*]    newFrame1newFrame1.origin.y =newFrame1.origin.y+50;   
[*]    ;   
[*]}   
[*]@end
源代码:http://easymorse-iphone.googlecode.com/svn/trunk/scrollLayer/
小结:IOS应用程序跑马灯效果案例的内容介绍完了,希望本文对你有所帮助!
【编辑推荐】

[*]IOS 4中实现UI自动测试教程
[*]iOS应用开发之Objective-C学习点滴
[*]详解IOS应用程序测试过程
[*]IOS应用程序资源管理教程
[*]解析XCode构造之如何启动iOS应用程序
[*]浅谈iOS图形图像技术Core Animation
页: [1]
查看完整版本: IOS应用程序跑马灯效果案例