[轉(zhuǎn)]UITableView中cell點擊的絢麗動畫效果

轉(zhuǎn):http://www.cnblogs.com/YouXianMing/p/4187996.html

這個鏈接中的代碼也實現(xiàn)了這種效果

https://github.com/cbpowell/MarqueeLabel

最終效果如下:

原理如下:

1. 獲取文本

2. 計算文本寬度

3. 將這個Label放入ScrollView中

4. 將ScrollView的contentSize的寬度設置與文本寬度一致

5. 做動畫

*6. 邊緣的漸隱效果請使用帶透明像素的PNG圖片

//

//RootViewController.m

//

//Copyright (c) 2014年 Y.X. All rights reserved.

//

#import"RootViewController.h"

#import"YXKit.h"

#import"FontPool.h"

@interfaceRootViewController ()

@end

@implementationRootViewController

- (void)viewDidLoad

{

[super viewDidLoad];

self.view.backgroundColor=[UIColor blackColor];//注冊字體

REGISTER_FONT(bundleFont(@"新蒂小丸子體.ttf"),@"新蒂小丸子體");//獲取文本

NSString *string=@"喜歡這首情思幽幽的曲子,仿佛多么遙遠,在感嘆著前世的情緣,又是那么柔軟,在祈愿著來世的纏綿?!渡彽男氖隆罚闼屏鹆б粯拥木К?,柔柔地撥動我多情的心弦。我,蓮的心事,有誰知?我,蓮的矜持,又有誰懂?";

//初始化label

UILabel *label? ? ? = [UILabelnew];

label.text=string;

label.numberOfLines=0;

label.textColor=[UIColor cyanColor];

label.font= [UIFont fontWithName:CUSTOM_FONT(@"新蒂小丸子體",0)

size:20.f];

//計算尺寸

CGSize size? ? ? ? = [label boundingRectWithSize:CGSizeMake(0,0)];

label.frame=(CGRect){CGPointZero, size};

//初始化

ScrollViewUIScrollView *showView =\

[[UIScrollView alloc] initWithFrame:CGRectMake(0,90,320, size.height)];

showView.contentSize=size;

showView.showsHorizontalScrollIndicator=NO;

[showView addSubview:label];

[self.view addSubview:showView];

//形成邊緣的遮罩

UIImageView *imageView =\

[[UIImageView alloc] initWithFrame:CGRectMake(0,90,320, size.height)];

imageView.image= [UIImage imageNamed:@"bg"];

[self.view addSubview:imageView];

//動畫

[UIView animateKeyframesWithDuration:10delay:7options:UIViewKeyframeAnimationOptionAllowUserInteraction

animations:^{

//計算移動的距離

CGPoint point =showView.contentOffset;

point.x= size.width -320.f;

showView.contentOffset=point;

}

completion:^(BOOL finished) {

}];

}@end

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容