在iOS应用程序中从下往上移动字幕样式的字幕样式。我已经尝试了很长一段时间使用谷歌搜索,但我不能得到完美的答案这个问题,请提供任何代码为这个问题。我是一个新的iOS应用程序。从下往上移动文字,如使用textView的iOS应用程序中的字幕样式
回答
试试这个
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
NSTimer *timer;
UILabel *label ;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
timer =[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scrollText:) userInfo:nil repeats:YES];
label = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 250, 20)];
label.text [email protected]"This is a string to be scroll";
[self.view addSubview:label];
}
-(void)scrollText:(id)parameter{
if (label.frame.origin.y <= 50) {
[label setFrame:CGRectMake(label.frame.origin.x, 400, label.frame.size.width, label.frame.size.height)];
}
else
[label setFrame:CGRectMake(label.frame.origin.x, label.frame.origin.y-5, label.frame.size.width, label.frame.size.height)];
}
@end
感谢您的回答了我的工作..... – user3331020
我有一个疑问......文字不能完全滚动到顶部.... – user3331020
让您的标签y位置为0 [的UILabel页头] initWithFrame:方法CGRectMake(20 ,0,250,20)];并在scrollText:方法if(label.frame.origin.y <= 0){[label setFrame:CGRectMake(label.frame.origin.x,self.view.frame.size.height - 20,label.frame.size .WIDTH,label.frame.size.height)];} – Rajesh
您可以在下面的链接中找到相同的实现。这对于COCOA CONTROL来说非常棒。
检查这个答案。
.H
NSTimer *timer;
float timeDuration;
.M
-(void)viewDidLoad {
[super viewDidLoad];
timeDuration=1.0f;
timer = [NSTimer scheduledTimerWithTimeInterval:timeDuration target:self selector:@selector(marqueeAnimation) userInfo:nil repeats:YES];
}
-(void)marqueeAnimation{
UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(100, -100, 100, 100)];
[imgView setImage:[UIImage imageNamed:@"root.PNG"]];
[self.view addSubview:imgView];
NSString *keyPath = @"transform.translation.y";
CAKeyframeAnimation *translation = [CAKeyframeAnimation animationWithKeyPath:keyPath];
translation.duration = timeDuration;
translation.autoreverses = NO;
NSMutableArray *values = [[NSMutableArray alloc] init];
[values addObject:[NSNumber numberWithFloat:0.0f]];
CGFloat height = [[UIScreen mainScreen] applicationFrame].size.height;
[values addObject:[NSNumber numberWithFloat:height]];
translation.values = values;
NSMutableArray *timingFunctions = [[NSMutableArray alloc] init];
[timingFunctions addObject:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
translation.timingFunctions = timingFunctions;
[imgView.layer addAnimation:translation forKey:keyPath];
}
感谢您的重播.... – user3331020
哇.. !!你很聪明。 – Optimistic
试试这个。这工作。在示例应用程序中尝试此操作,然后将其包含在您的应用程序中
#import "ViewController.h"
@interface ViewController()
@property(nonatomic, retain) NSTimer *timer;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_txtView setText:@"hi..."];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(marqueeScroll) userInfo:nil repeats:YES];
}
-(void) marqueeScroll
{
[_txtView setFrame:CGRectMake(_txtView.frame.origin.x, _txtView.frame.origin.y-1.0, _txtView.frame.size.width, _txtView.frame.size.height)];
CGRect screen = [[UIScreen mainScreen] bounds];
if(_txtView.frame.origin.y <= 0)
{
[_txtView setFrame:CGRectMake(_txtView.frame.origin.x, screen.size.height,_txtView.frame.size.width, _txtView.frame.size.height)] ;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
让我知道是否有任何错误。
- 1. 在网页上滑动的应用程序样式的屏幕
- 2. 文字显示从下往上qt
- 3. iOS移动应用程序中的初始屏幕(Swift)
- 4. IOS Scrollview字幕样式
- 5. iOS应用程序中的自定义字体的粗体字体样式
- 6. 将文件从iOS移动应用程序上传到SharePoint
- 7. 在iOS应用程序中使用动态文本的样式按钮
- 8. 从上往下移动背景图像
- 9. 更改textview时,textview下方按钮上的文字向下移动。帮帮我!
- 10. 移动本机应用程序中的字体脸部使用
- 11. 移动Web应用程序:在iOS上下载附件
- 12. 如何在iOS中更改textview的字体系列和样式?
- 13. 在iOS 5上禁用字幕会在屏幕上留下最后显示的字幕文字
- 14. TextView字幕移位相邻TextView
- 15. 使用CookieSyncManager.createInstance中的应用程序或活动上下文
- 16. 在Flex移动应用程序样式按钮栏字体 - 用截图附
- 17. 移动web应用程序的表单字段中的文件上传
- 18. iOS上的Phonegap应用程序 - 页面上的文字输入焦点滚动
- 19. 从iOS应用程序中检测附近的移动设备
- 20. 在Uber iOS应用程序上移动地图上的注释
- 21. 从Appstore下载的应用程序挂在ios 8.1.2的第一个屏幕上?
- 22. 如何在我的Android应用程序中使用“字体样式”?
- 23. 从iOS应用程序发布我墙上的字符串?
- 24. 使用sharekit从iOS应用程序分享facebook上的文本
- 25. 从外部控件中的应用程序中使用样式
- 26. iOS上传文件从应用程序
- 27. 如何像TextView的字幕一样动画图像
- 28. iOS应用程序从屏幕顶部偏移
- 29. 应如何将新应用程序版本的iOS应用程序数据文件从NSDocumentDirectory移动到NSLibraryDirectory?
- 30. 如何在iOS上的本地Facebook应用程序中打开Safari中的移动Web应用程序链接?
检查我对这个问题的答案你刚刚有只TIMEDURATION完成动画1时则设置重复 –
后哇.. !!你很聪明。 – Optimistic