iPhone UIImageView 动画问题

标签 iphone uiimageview

我在使用 UIImageView 动画时遇到一些问题。我创建了三个包含图像的 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.

最佳答案

我认为您需要保留您在viewDidLoad中创建的三个数组——您永远不会对它们调用alloc,所以您不需要在您调用 retain 之前,不拥有所有权。

关于iPhone UIImageView 动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/727180/

相关文章:

ios - UIScrollView 框架在 iOS 8 和 iOS 7 上的大小不同

ios - 在嵌入 UIView 的 UItableview 中的原型(prototype)单元中显示自定义 UIimageview

iphone - 全屏 UIImageView 中的横向模式图像

objective-c - 要 float 的 TextField 文本(Objective-C)

iphone - 选择单元格时更改标签属性

iphone - UIViewAnimationOptionRepeat在两个动画之间暂停

objective-c - 我应该使用哪个第三方 Imageview 类?

iphone - iOS OpenGL ES 2.0 : Offscreen render and save the result to an UIImage

php - 如何用 PHP 解密 iPhone 加密的 AES256 文本

ios - 图片只全屏显示一次