【发布时间】:2011-03-29 11:07:17
【问题描述】:
我正在尝试制作一个简单的动画,当单击按钮时会连续旋转图像,但由于某种原因,当我单击按钮时,它会使应用程序崩溃。
这是我的代码。
.h 文件:
@interface MainView : UIView {
}
IBOutlet UIImageView *sunray;
- (IBAction)pushrotate:(id)sender;
@end
.m 文件:
@implementation MainView
- (IBAction)pushrotate:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0];
sunray.transform = CGAffineTransformMakeRotation(6.2831855);
[UIView commitAnimations];
}
-(void) dealloc {
[sunray dealloc];
[sunray release];
[super dealloc];
}
@end
知道如何让它发挥作用吗?另外,让应用加载后立即开始动画的最佳方法是什么?
【问题讨论】:
-
你检查过 sunray 是否不是 nil 吗?你在IB中正确连接了吗?
-
如果它崩溃了,那么你的按钮可能连接不正确。请在崩溃后在控制台上提供消息。
-
是的,错误代码在抛出“NSException”实例后被终止调用,我确实为按下按钮进行了内部修饰。
-
永远不要直接发送dealloc消息。 [sunray release] 应该对任何人都足够了。
标签: iphone objective-c xcode ios4