0

uiview で imageview と 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内で画像ビューとテキストビューの両方を一緒にアニメーション化する方法.

手伝ってくれてありがとう。

4

1 に答える 1

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;

}
于 2013-02-03T21:56:02.987 に答える