在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應用程序中的自定義字體的粗體字體樣式
- 5. IOS Scrollview字幕樣式
- 6. 將文件從iOS移動應用程序上傳到SharePoint
- 7. 在iOS應用程序中使用動態文本的樣式按鈕
- 8. 從上往下移動背景圖像
- 9. 更改textview時,textview下方按鈕上的文字向下移動。幫幫我!
- 10. 移動本機應用程序中的字體臉部使用
- 11. 如何在Spring Web應用程序中將數據從Session的屬性移動到應用程序上下文?
- 12. 移動Web應用程序:在iOS上下載附件
- 13. 應用屏幕向下移動(iOS設備上)
- 14. 在IOS中使用iframe的移動首次應用程序
- 15. 如何在iOS中更改textview的字體系列和樣式?
- 16. 在iOS 5上禁用字幕會在屏幕上留下最後顯示的字幕文字
- 17. 使用CookieSyncManager.createInstance中的應用程序或活動上下文
- 18. TextView字幕移位相鄰TextView
- 19. 在Flex移動應用程序樣式按鈕欄字體 - 用截圖附
- 20. 移動web應用程序的表單字段中的文件上傳
- 21. iOS上的Phonegap應用程序 - 頁面上的文字輸入焦點滾動
- 22. 從iOS應用程序中檢測附近的移動設備
- 23. 在Uber iOS應用程序上移動地圖上的註釋
- 24. 從Appstore下載的應用程序掛在ios 8.1.2的第一個屏幕上?
- 25. 如何在我的Android應用程序中使用「字體樣式」?
- 26. 使用sharekit從iOS應用程序分享facebook上的文本
- 27. 從iOS應用程序發佈我牆上的字符串?
- 28. 從外部控件中的應用程序中使用樣式
- 29. iOS上傳文件從應用程序
- 30. 從下往上滾動ListView
檢查我對這個問題的答案你剛剛有隻TIMEDURATION完成動畫1時則設置重複 –
後哇.. !!你很聰明。 – Optimistic