我有一些问题的UIImageView动画。我已经创建了一个包含了图像3个NSArray的对象,并创建了一个采取一个UIImageView三种方法和新的动画分配给它。它的工作原理奇妙的调用首次三种方法之一,但这样做另一次崩溃模拟器和设备。任何想法?

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

// set the anims
slowAnimation = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"image1.jpg"],
                    [UIImage imageNamed:@"image2.jpg"],
                                nil];
defaultAnimation = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"image3.jpg"],
                    [UIImage imageNamed:@"image4.jpg"],
                        nil];
fastAnimation = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"image5.jpg"],
                    [UIImage imageNamed:@"image6.jpg"],
                    nil];

// load the default speed - this works once, but when applied a second time it crashes the simulator and device
[self setDefaultAnim:myUIImageViewObject];

[super viewDidLoad];
}


// animation switcher
-(void)setSlowAnim:(UIImageView *)imageView
{
    [imageView stopAnimating];
    imageView.animationImages = slowAnimation;
    imageView.animationDuration = 0.4;
    [imageView startAnimating];
}
-(void)setDefaultAnim:(UIImageView *)imageView
{
    [imageView stopAnimating];
    imageView.animationImages = defaultAnimation;
    imageView.animationDuration = 0.4;
        [imageView startAnimating];
}
-(void)setFastAnim:(UIImageView *)imageView
{
    [imageView stopAnimating];
    imageView.animationImages = fastAnimation;
    imageView.animationDuration = 0.4;
   [imageView startAnimating];
}

错误日志:

[Session started at 2009-04-06 22:46:54 +0100.]
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
warning: Unable to read symbols for "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics" (file not found).
warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory).
Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/hello/Library/Application Support/iPhone Simulator/User/Applications/6DB7C45D-1A26-4775-9AE3-C30F3EBC9F83/PlateSpinner.app/PlateSpinner', process 345.
kill
quit

The Debugger has exited with status 0.
有帮助吗?

解决方案

我想你需要retain您在viewDidLoad创建三个数组 - 你永远不会要求他们alloc,所以你没有所有权做,直到你调用retain

其他提示

而不是仅仅调用保留使用initWithObjects消息:

slowAnimation = [[NSArray alloc] initWithObjects:
                                  [UIImage imageNamed:@"image1.jpg"],
                                  [UIImage imageNamed:@"image2.jpg"],
                                  nil];

如果你做了什么酒廊建议,不过,请注意,您将需要稍后释放slowAnimation对象。既然你alloc'd它,它就会有1保留计数,直到有人告诉运行时除外。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top