我正在编写一个iPhone应用程序,并按照此问题中的建议将常量排列在Constants.h和Constants.m文件中:Objective-C中的常量.
我的问题是,如果我在Constants.h中定义一个typedef枚举,并想在我的一个.h文件中声明该typedef枚举的属性,那么实现它的正确方法是什么?我是否需要将constdef枚举移出Constants.h和类.h文件?似乎打败了拥有全局常量文件的目的......
我有以下代码:
if (self.graphic.fillColor)
{
CGContextSetFillColorWithColor(context, self.graphic.fillColor);
CGContextDrawPath(context, kCGPathFill);
}
if (self.graphic.strokeColor)
{
CGContextSetStrokeColorWithColor(context, self.graphic.strokeColor);
CGContextSetLineWidth(context, self.graphic.strokeWidth);
CGContextDrawPath(context, kCGPathStroke);
}
Run Code Online (Sandbox Code Playgroud)
在某种情况下,我正在加载一个有a fillColor和a 的图形对象strokeColor.当我这样做,填充完毕,但行程完全不抽(我已仔细检查,看看是否有与行程值的分配任何错误,并且一切正常).为什么是这样?如果你在一起做这两个,你需要同时做这两个CGContextDrawPath吗?
我在用于iPhone的Objective-C/Cocoa-Touch编码,我想知道,不链接初始化器是否可行?例如,在我的父类中,我有三个初始化器,它们都需要由子类继承.在这种情况下可以不链接吗?例如,在这一个课程中我设置如下:
- (id)initWithGraphic:(Graphic*)graphic size:(CGSize)size
{
self = [super initWithFrame:CGRectZero];
if (self)
{
...
}
return self;
}
- (id)initWithGraphic:(Graphic*)graphic maximumDimension:(CGFloat)maximumDimension
{
self = [super initWithFrame:CGRectZero];
if (self)
{
...
}
return self;
}
- (id)initWithGraphic:(Graphic*)graphic
{
self = [super initWithFrame:CGRectZero];
if (self)
{
...
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我没有一个指定的初始化器,因为我很难把它们连在一起,我基本上有三个.
我正在尝试将一个简单的数组写入plist文件,然后再检索它.我有以下代码:
+ (NSString*) dataFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *dataFilePath = [documentDirectory stringByAppendingPathComponent:@"TipAlertViewDefaults.plist"];
return dataFilePath;
}
+ (NSArray*) tipAlertViewDefaults
{
NSString *dataFilePath = [self dataFilePath];
NSLog(@"DataFilePath: %@", dataFilePath);
NSMutableArray *tipAlertViewDefaults;
if ([[NSFileManager defaultManager] fileExistsAtPath:dataFilePath])
{
NSLog(@"File Exists");
tipAlertViewDefaults = [[NSMutableArray alloc] initWithContentsOfFile:dataFilePath];
}
else
{
NSLog(@"File Doesn't Exist");
tipAlertViewDefaults = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithBool:NO], nil];
[tipAlertViewDefaults writeToFile:dataFilePath atomically:YES];
}
return tipAlertViewDefaults;
}
Run Code Online (Sandbox Code Playgroud)
我调用这个方法两次,在第一次它不应该找到文件并且第一次写它.然后第二个调用应该能够找到该文件,但事实并非如此.有人能看到我在哪里错了吗?
我想知道是否有人有一个聪明的方法来检查一个对象是否类型UIKeyboard?我不能使用UIKeyboardDidShow通知,因为我使用它们来调出除键盘之外的其他inputView类,所以我必须能够区分哪个inputView当前在屏幕上(即我有一个弹出一个屏幕上有一个控制面板,可以让你改变某些东西的颜色).
使用[view isKindOfClass:[UIKeyboard class]]不起作用,因为无法识别UIKeyboard,我无法导入它的.h文件而不会出现错误.
有谁知道我能在这做什么?
在以下屏幕截图中:

当你拖动单词气球的尾部(从气球连接到人口的东西)时,形状曲线(如图中两个气球尾部之间的差异所示).我想知道,这是怎么做到的?我假设你需要从一个CGPath开始并做一些事情,有没有人碰巧知道这是什么?
更新:如果我想弯曲以下形状:

我会使用以下代码:
CGPathAddCurveToPoint(mutablePath, NULL, x1, y1, x2, y2 + constant, x5, y5);
CGPathAddCurveToPoint(mutablePath, NULL, x3, y3, x4, y4 + constant, x5, y5);
Run Code Online (Sandbox Code Playgroud)
常量是否重新调整点2和点4的y位置以形成曲线?
假设我有*x类的对象Illustration.使用x,我想将它的类名提取到一个字符串,所以我有@"Illustration".是否有可能做到这一点?