我想在uiview中一起整理imageview和textview数组。
现在我正在动画图像视图分离和textview分开,这看起来不那么好。
UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)];
baseView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:252.0/255.0 blue:199.0/255.0 alpha:1.0];
[self.view addSubview:baseView];
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 30, 200, 200)];
self.imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
nil];
// all frames will execute in 25 seconds
self.imageView.animationDuration = 20;
[self.imageView startAnimating];
[baseView addSubview:self.imageView];
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 250, 300, 200)];
self.textView.textColor = [UIColor brownColor];
myArray = [[NSMutableArray alloc] initWithObjects:@"string1", @"string2", @"string3", @"string4", @"string5", ...., nil];
[NSTimer scheduledTimerWithTimeInterval:2.5
target:self
selector:@selector(updateText:)
userInfo:nil
repeats:YES];
[baseView addSubview: self.textView];
- (void)updateText:(NSTimer *)theTimer
{
if (index < [myArray count])
{
self.textView.text = [self.myArray objectAtIndex:index];
index++;
}
else
index = 0;
[timer invalidate];
}
如何在UIView中同时为图像视图和textview设置动画。
感谢您的帮助。
答案 0 :(得分:1)
这个怎么样,
在你的.h
NSArray *imgsArray;
NSArray *myArray;
int indx;
NSTimer *timer;
并开始动画
-(void)start{
imgsArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"],[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],nil];
myArray = [[NSMutableArray alloc] initWithObjects:@"string1", @"string2", @"string3", @"string4", @"string5", nil];
timer = [NSTimer scheduledTimerWithTimeInterval:2.5
target:self
selector:@selector(updateText:)
userInfo:nil
repeats:YES];
}
- (void)updateText:(NSTimer *)theTimer
{
if (indx < myArray.count)
{
self.textView.text = [self.myArray objectAtIndex:indx];
self.imageView.image = [self.imgsArray objectAtIndex:indx];
indx++;
}
else
indx = 0;
}