这是我上一期的问题.我正在使用beginAnimations:context:设置动画块来动画一些UITextLabels.但是我在文档中注意到:"在iOS 4.0及更高版本中不鼓励使用此方法.您应该使用基于块的动画方法."
我的问题是我很想使用animateWithDuration:动画:(在iOS 4.0及更高版本中可用)但不想排除使用iOS 3.0的人.有没有办法在运行时检查设备的iOS版本,以便我可以决定使用哪个语句?
我已将下面的两种方法连接到我的UI中的单独按钮,但是注意到按下"VERSION 1"按钮后我再也无法按下按钮,直到方法中的动画持续时间结束.我的理解是动画使用自己的线程,以免阻塞主应用程序.
// VERSION 1
-(IBAction)fadeUsingBlock {
NSLog(@"V1: Clicked ...");
[myLabel setAlpha:1.0];
[UIView animateWithDuration:1.5 animations:^{
[myLabel setAlpha:0.0];
}];
}
Run Code Online (Sandbox Code Playgroud)
较旧的样式版本(下方)允许在动画计时器结束之前按下按钮,只需将计时器重置为重新开始.如果这些都是相同的,我是否遗漏了某些东西,或者3.2和4之间的操作有变化吗?
// VERSION 2
-(IBAction)fadeUsingOld {
NSLog(@"V2: Clicked ...");
[myLabel setAlpha:1.0];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[myLabel setAlpha:0.0];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
干杯加里
我只是想,因为如果我创建其中两个然后将它们添加到NSArray中,你可以将块视为对象,是否有办法从数组中执行它们?
int (^Block_001)(void) = ^{ return 101; };
int (^Block_002)(void) = ^{ return 202; };
NSArray *array = [NSArray arrayWithObjects:Block_001, Block_002, nil];
Run Code Online (Sandbox Code Playgroud)
编辑:更新清晰Per @ davedelong的优秀答案
int (^Block_001)(void) = [^{ return 101; } copy];
int (^Block_002)(void) = [^{ return 202; } copy];
NSArray *array = [NSArray arrayWithObjects:Block_001, Block_002, nil];
[Block_001 release];
[Block_002 release];
Run Code Online (Sandbox Code Playgroud) 我对SKNode方法convertPoint:fromNode:和convertPoint:ToNode:工作方式感到有些困惑,我看过文档,但不是很明显他们做了什么.例如,这个(见下图)是我用过的一个小测试convertPoint:fromNode:.黑色区域是SKScene背景,蓝色区域是一个SKSpriteNode父级SKScene,红色区域是另一个SKSpriteNode蓝色精灵的父级.两个精灵的锚点由小绿点表示.我想要做的是获取红色精灵的场景位置,我使用以下代码完成:
CGPoint positionInScene = [self convertPoint:[self position]
fromNode:[self redSprite]];
Run Code Online (Sandbox Code Playgroud)
结果是这样的
positionInScene = [105, 205]
Run Code Online (Sandbox Code Playgroud)
这是我所期望的,因为那将是场景空间中红色方块的起源.我很困惑的是争论.根据我的猜测:
[SKNode_A convertPoint: CGPoint_B toNode: SKScene_C]
Run Code Online (Sandbox Code Playgroud)
我最初的尝试是[self convertPoint:[redSprite position] fromNode:redSprite]因为我想将红色精灵原点转换为场景.如果有人能在这个和它的朋友身上投入一点点光明和逻辑,convertPoint:toNode:那将会非常感激,这似乎有点笨拙.

我@selector今天第一次使用,并且无法弄清楚如何做以下事情?@selector如果你有一个以上的论点,你会怎么写?
没有参数:
-(void)printText {
NSLog(@"Fish");
}
[self performSelector:@selector(printText) withObject:nil afterDelay:0.25];
Run Code Online (Sandbox Code Playgroud)
单一论点:
-(void)printText:(NSString *)myText {
NSLog(@"Text = %@", myText);
}
[self performSelector:@selector(printText:) withObject:@"Cake" afterDelay:0.25];
Run Code Online (Sandbox Code Playgroud)
两个论点:
-(void)printText:(NSString *)myText andMore:(NSString *)extraText {
NSLog(@"Text = %@ and %@", myText, extraText);
}
[self performSelector:@selector(printText:andMore:) withObject:@"Cake" withObject:@"Chips"];
Run Code Online (Sandbox Code Playgroud)
多个参数:(即超过2个)
什么是使用Objective-C获得当前时间(HH:MM:SS)的最佳方法.我猜我应该看看NSDate和NSDateFormatter.我快速浏览了一下文档,它看起来比我想象的更复杂,所以我想我会在这里检查以确保我在正确的轨道上.
加里
快速提问,有没有人知道如何以编程方式使textField中的文本变为粗体或斜体?
@property(nonatomic, retain) IBOutlet UITextField *textField_TOP_01;
[textField_TOP_01 setTextColor:[UIColor redColor]];
[textField_TOP_01 setText:@"This text is bold"];
Run Code Online (Sandbox Code Playgroud)
非常感激
加里
从内部rootController我手动添加UITableView,但我不知道如何获得帧大小...
Controller *rootController = [[Controller alloc] init];
UINavigationController *tempNavController = [[UINavigationController alloc] initWithRootViewController:rootController];
[self setNavController:tempNavController];
[tempNavController release];
[window addSubview:[[self navController] view]];
[window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)
我目前正在使用:[[[self navigationController] view] frame]但这并未考虑"navBar"高度或"statusBar"的高度(给我:480).有没有办法让帧大小低于statusBar/navBar,还是我必须从上面的数字中减去20 + 44?
NB:我用navigationController.navigationBar.frame.size.height44来
无论如何从"createFileAtPath"获取更详细的错误数据我有点期待NSError?目前我正在使用BOOL返回值.
success = [fileMan createFileAtPath:fileOnDisk contents:dBuffer attributes:nil];
if(success == YES) NSLog(@"FileCreated");
else {
NSLog(@"ERROR: Failed to create file");
return 1;
}
Run Code Online (Sandbox Code Playgroud)
加里
在Interface Builder中使用UI项目时,有任何方法可以在项目位置满意后锁定项目的位置吗?我只是问我在选择它们进行编辑时会略微拖动项目,导致必须返回并调整位置.
objective-c ×8
iphone ×7
cocoa-touch ×6
animation ×1
ios7 ×1
nsarray ×1
sknode ×1
sprite-kit ×1