我正在AppDelegate中创建一个数组,然后想在另一个视图控制器中使用它(连续重复直到我关闭视图)。它填充数组,但似乎没有动画。我已经搜索并进行了几天的编辑。任何帮助,将不胜感激!
AppDelegate.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) NSMutableArray *sharedArray1;
@end
AppDelegate.m
#import "Scene1.h"
@synthesize sharedArray1;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
int ii;
for (ii = 1; ii<70;) {
[sharedArray1 addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"RadarCircle_Active%i.png", ii] ofType:nil]]]];
NSLog(@"Log RadarCircle_Active i: %i",ii);
ii = ii + 1; // increment by 1
}
return YES;
}
Scene1.m
#import "AppDelegate.h"
-(void)radarActive{
float duration1 = 5.5;
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
activeRadarImage.animationImages = appDelegate.sharedArray1;
activeRadarImage.animationDuration = duration1;
// activeClawImage.animationRepeatCount = count;
[activeRadarImage startAnimating];
}
答案 0 :(得分:0)
在我看来,您需要在开始向其添加对象之前将sharedArray1
设置为某些内容。
在开始循环之前尝试添加它:
self.sharedArray1 = [[NSMutableArray alloc] init];
答案 1 :(得分:0)
正如@architectpianist所说,你需要先分配并尝试更改
[sharedArray1 addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"RadarCircle_Active%i.png", ii] ofType:nil]]]];
到
[sharedArray1 addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"RadarCircle_Active%i", ii] ofType:@"png"]]]];
或者你可以这样做
NSString *imageName = [NSString stringWithFormat:@"RadarCircle_Active%i.png", ii];
UIImage *image = [UIImage imageNamed:imageName];
NSLog(@"image : %@", image);
[sharedArray1 addObject:image];
查看NSLog。
希望它有所帮助。