在 iOS 应用程序中从下到上移动类似选取框样式的文本。我已经使用谷歌搜索尝试了很长时间,但我无法得到这个问题的完美答案,请提供这个问题的任何代码。我是 iOS 应用程序的新手。
问问题
708 次
4 回答
1
尝试这个
#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 =@"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
于 2014-02-20T04:41:17.257 回答
1
检查这个答案。
。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];
}
于 2014-02-20T04:58:53.593 回答
0
您可以在下面的链接中找到相同的实现。这对 COCOA CONTROL 来说真是太棒了。
于 2014-02-20T04:39:41.310 回答
0
尝试这个。这行得通。在示例应用程序中尝试此操作,然后将其包含在您的应用程序中。
#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
让我知道是否有任何错误。
于 2014-02-20T05:32:21.460 回答