0

大家好,我一直在尝试开发一个 cydia,它将在 UIImageView 中为图像设置动画,我认为我的代码都很好,但由于某种原因,应用程序每次执行任务时都会崩溃。我已经读过这可能是一次加载太多图像的原因,但我只尝试加载 2 个小 png 图像,所以我认为这不是原因。请让我知道你的想法!

%hook UISaveToCameraRollActivity
-(void)performActivity {
%orig;
NSBundle *bundle = [[NSBundle alloc] initWithPath:kBundlePath];
NSString *imagePath = [bundle pathForResource:@"hand" ofType:@"png"];
NSString *imagePath1 = [bundle pathForResource:@"floppy" ofType:@"png"];
UIWindow *statusWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]
bounds]];
statusWindow.windowLevel = UIWindowLevelStatusBar;
statusWindow.hidden = NO;
statusWindow.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
UIImageView *pic = [[UIImageView alloc] initWithFrame:CGRectMake (0, 0, 69, 69)];
pic.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"hand.png"],
[UIImage imageNamed:@"floppy.png"], nil];
pic.animationDuration = 1.0f;
[pic startAnimating];
pic.animationRepeatCount = 0;
[pic release];
pic.center = statusWindow.center;
pic.image = [UIImage imageWithContentsOfFile:imagePath];
pic.image = [UIImage imageWithContentsOfFile:imagePath1];
[statusWindow addSubview:pic];
[statusWindow makeKeyAndVisible];

}
%end
4

1 回答 1

1

移动:

[pic release];

到你的方法结束。一旦你释放它,你永远不应该与一个对象进行交互,这几乎可以保证你的应用程序崩溃。

如果你不想为手动管理内存而烦恼,你应该试试 ARC:

https://developer.apple.com/library/ios/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html

于 2014-01-03T20:27:37.210 回答