0

所以,我最初用来设置图像的代码(它通过蓝牙从另一个 iOS 设备接收数据)

    UIImage *receivedImage = [UIImage imageWithData:data];
        if(receivedImage != nil)
        {
            NSLog(@"Image received is not nil.");
        }
        self.imageView.image = receivedImage;
        UIImageView *iv = [[UIImageView alloc] initWithImage:receivedImage];
        [self.view addSubview:iv];

        [self.photoAlbum addObject:receivedImage];

设置图像就像一个魅力。

但是,当我尝试将其添加到 NSMutableArray 属性“专辑”时,图像不会改变。

  -(void)stereoscopicIterationA {
    self.imageView.image = nil;
    self.imageView.image = [self.photoAlbum objectAtIndex:1];
    NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(stereoscopicIterationB) userInfo:nil repeats:NO];
    NSLog(@"Image 1");

}

-(void)stereoscopicIterationB {
    self.imageView.image = nil;
    self.imageView.image = [self.photoAlbum objectAtIndex:0];
    NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(stereoscopicIterationA) userInfo:nil repeats:NO];
    NSLog(@"Image 0");
}

-(void)openAlbum:(id)sender
{

    if([self.photoAlbum objectAtIndex:0] != nil && [self.photoAlbum objectAtIndex:1] == nil)
    {
    self.imageView.image = [self.photoAlbum objectAtIndex:0];


    [self dismissModalViewControllerAnimated:NO];
    }
    else if([self.photoAlbum objectAtIndex:0] !=nil && [self.photoAlbum objectAtIndex:1] !=nil ){
        //Set up NSTimer to swap self.imageView.image back and forth between 0 and 1 of photoAlbum.
        NSLog(@"Timer set up");
        NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(stereoscopicIterationA) userInfo:nil repeats:YES];

    }

有任何想法吗?

更具体地说,看起来图像根本没有添加/保存到专辑 NSMutableArray 中。程序因越界错误 [0 .. 0] 而崩溃。

4

2 回答 2

0

如果您只想要两个图像的动画,您可以制作它们的数组并将其设置为animationImages属性,然后调用startAnimating.

self.imageView.animationImages = self.photoAlbum;
[self.imageView startAnimating];

然后你也可以设置animationDurationanimationRepeatCount属性。

于 2012-07-28T06:12:48.480 回答
0

听起来,从更新到您的问题,好像self.photoAlbumnil. 您需要确保已分配数组,并将其分配到self.photoAlbum.

做这个:

self.photoAlbum = [[NSMutableArray alloc] init];

在尝试添加到数组之前。

于 2012-07-28T06:16:30.937 回答