문제

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.
도움이 되었습니까?

해결책

나는 당신이 필요하다고 생각합니다 retain 당신이 만든 세 배열 viewDidLoad - 당신은 결코 전화하지 않습니다 alloc 그들에게 전화 할 때까지 소유권이 없습니다. retain.

다른 팁

retain을 호출하는 대신 initwithobjects 메시지를 사용하십시오.

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

라운지가 제안한 것을 수행하면 나중에 슬로 니화 물체를 해제해야합니다. 당신이 그것을 할당했기 때문에, 누군가가 런타임을 말할 때까지 1의 유지 카운트가 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top