我正在尝试使用iPhone OS 4.0(iOS4?)SDK实现游戏.在以前版本的SDK中,我一直在使用[UIView beginAnimations:context:]和[UIView commitAnimations]来创建一些动画.但是,当我查看4.0中函数的文档时,我看到了这个注释.
在iPhone OS 4.0及更高版本中不鼓励使用此方法.您应该使用基于块的动画方法.
你可以在这里找到它:http: //developer.apple.com/iphone/library/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/commitAnimations
我的问题是,iPhone OS 4.0中基于块的动画是什么?我虽然beginAnimations:context:和commitAnimations函数用于创建动画块..
我正在尝试创建一个用户可以添加条目的iPhone应用程序.当他按下一个新条目时,会弹出一个框,询问他一些信息.然后他可以按"取消"或"保存"以丢弃数据或将其保存到磁盘.
为了保存,我使用的是Core Data框架,它运行得很好.但是,我无法使用"取消"按钮.当窗口弹出,询问信息时,我在托管对象上下文(MOC)中创建一个新对象.然后当用户按下取消时,我尝试使用属于MOC的NSUndoManager.
我还想使用嵌套的撤消组来执行此操作,因为可能存在嵌套组.
为了测试这个,我写了一个简单的应用程序.该应用程序只是启用了Core Data的"基于Window的应用程序"模板.对于Core Data模型,我创建了一个名为"Entity"的实体,其整数属性为"x".然后在applicationDidFinishLaunching中,我添加以下代码:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
unsigned int x=arc4random()%1000;
[self.managedObjectContext processPendingChanges];
[self.managedObjectContext.undoManager beginUndoGrouping];
NSManagedObject *entity=[NSEntityDescription insertNewObjectForEntityForName:@"Entity"
inManagedObjectContext:self.managedObjectContext];
[entity setValue:[NSNumber numberWithInt:x] forKey:@"x"];
NSLog(@"Insert Value %d",x);
[self.managedObjectContext processPendingChanges];
[self.managedObjectContext.undoManager endUndoGrouping];
[self.managedObjectContext.undoManager undoNestedGroup];
NSFetchRequest *fetchRequest=[[NSFetchRequest alloc] init];
NSEntityDescription *entityEntity=[NSEntityDescription entityForName:@"Entity"
inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entityEntity];
NSArray *result=[self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
for(entity in result) {
NSLog(@"FETCHED ENTITY %d",[[entity valueForKey:@"x"] intValue]);
}
[window makeKeyAndVisible];
}
Run Code Online (Sandbox Code Playgroud)
这个想法很简单.尝试插入新的Entity对象,撤消它,获取MOC中的所有Entity对象并将其打印出来.如果一切正常,最后应该没有对象.
但是,我得到了这个输出:
[Session started at 2010-02-20 13:41:49 -0800.]
2010-02-20 13:41:51.695 …Run Code Online (Sandbox Code Playgroud)