运行core-plot example
下载sdk,地址https://code.google.com/p/core-plot/,我下载的是CorePlot_1.0
再readme文件下有两个说明文件:
README for Docs Install说明如何再xcode中安装帮助文档
README for Static Library Install 说明如何再项目中引入core-plot
我们先说一下如何运行CorePlot_1.0/Source/examples下面的example,我这次主要是要往ios中使用,因此试了几个example 只有“CorePlotGallery”符合我的要求,其他的或者是面向mac 的,或者是ios但编译不成功。
打开“Plot_Gallery_iOS.xcodeproj”,
由于core-plot是基于CorePlot-CocoaTouch.xcodeproj,因此project中包含了一个project。而且CorePlot-CocoaTouch.xcodeproj同一时间只能被一个工程使用,因此,如果你要多个工程同时运行的时候,需要将CorePlot_1.0拷贝一份,并在 header search path 中引入对应路径,如“/Users/user/Downloads/CorePlot_1.0/Source/framework/**”,注意,必须是递归
再target的build phase的target dependencies 中引入CorePlot-CocoaTouch,在 link binary with libraies中引入CorePlot-CocoaTouch中编译出来的libCorePlot-CocoaTouch.a,编译成功。
(注:我是在编译成功之后凭自己的记忆记录博客的,因此会有疏漏,但记录的都是我遇到比较典型的问题,希望对各位有帮助。)
这样子是调用了本地的源文件工程,不方便,我们可以摆脱CorePlot-CocoaTouch.xcodeproj的控制。过程如下。
移除 CorePlot-CocoaTouch.xcodeproj工程。将编译好的libCorePlot-CocoaTouch.a复制到frame下,并添加到target的link binary with libraies中,复制/CorePlot_1.0/Binaries/iOS/CorePlotHeaders文件夹到工程下
CorePlotGallery中,
Plots放置各种demo,
CorePlot-CocoaTouch.xcodeproj放置核心文件
**
出现错误:
2012-08-17 16:11:44.340 CorePlotTest3[21004:f803] -[__NSCFConstantString sizeWithTextStyle:]: unrecognized selector sent to instance 0x93cb8
2012-08-17 16:11:44.341 CorePlotTest3[21004:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString sizeWithTextStyle:]: unrecognized selector sent to instance 0x93cb8'
fix: build setting 的other linker flag 设为“-all_load -ObjC”
我刚开始设置的是(-ObjC-all_load ),出现上面错误,fuck!!!
****
再xcode4.4编译framework时候遇到错误:
clang: error: -Z-reserved-lib-stdc++: 'linker' input unused when '-c' is present
解决方法如下:
https://code.google.com/p/core-plot/source/detail?r=aec950cf7128#
google code提供了解决方案,我们只需删除所有的关键字“falign-loops”
Modify /framework/CorePlot-CocoaTouch.xcodeproj/project.pbxproj
Modify /framework/CorePlot-CocoaTouch.xcodeproj/project.pbxproj diff
...
1092 1092 GCC_ENABLE_SYMBOL_SEPARATION = YES;
1093 1093 GCC_OPTIMIZATION_LEVEL = 0;
1094 1094 INSTALL_PATH = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
1095 - OTHER_CFLAGS = (
1096 - "-lstdc++",
1097 - "-falign-loops=16",
1098 - );
1099 1095 OTHER_CPTLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
1100 1096 OTHER_LDFLAGS = (
1101 1097 "-all_load",
...
1114 1110 DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
1115 1111 GCC_ENABLE_SYMBOL_SEPARATION = YES;
1116 1112 INSTALL_PATH = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
1117 - OTHER_CFLAGS = (
1118 - "-lstdc++",
1119 - "-falign-loops=16",
1120 - );
1121 1113 OTHER_CPTLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
1122 1114 OTHER_LDFLAGS = (
1123 1115 "-all_load",
...
1153 1145 IPHONEOS_DEPLOYMENT_TARGET = 3.1.3;
1154 1146 MACH_O_TYPE = staticlib;
1155 1147 ONLY_ACTIVE_ARCH = YES;
1156 - OTHER_CFLAGS = "-falign-loops=16";
1157 1148 OTHER_LDFLAGS = (
1158 1149 "-all_load",
1159 1150 "-ObjC",
...
1192 1183 IPHONEOS_DEPLOYMENT_TARGET = 3.1.3;
1193 1184 MACH_O_TYPE = staticlib;
1194 1185 ONLY_ACTIVE_ARCH = NO;
1195 - OTHER_CFLAGS = "-falign-loops=16";
1196 1186 OTHER_LDFLAGS = (
1197 1187 "-all_load",
1198 1188 "-ObjC",
...
******
遇到错误:
NSString *newKey = [[NSString alloc] initWithFormat:@"CPTColor.component[%u]", i];
将%u改为%zu
ref:https://code.google.com/p/core-plot/source/detail?r=aec950cf7128#
*****
我在我的chat需要放在scroll view中使用,但拖动图表移动的动作会和scrollview冲突,下面是我的解决方案。
思路是当用户touch报表时候,将scroolview 的scroo 设为disable,但core plot 的点击事件是在哪里呢,在 CPTGraphHostingView 中的 #pragma mark Touch handling中
core plot的拦截了touch ,我们需要将touch事件继续向下传递。
在framework工程中,找到CPTGraphHostingView
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Ignore pinch or other multitouch gestures
if ( [[event allTouches] count] > 1 ) {
return;
}
CGPoint pointOfTouch = [[[event touchesForView:self] anyObject] locationInView:self];
if ( !collapsesLayers ) {
pointOfTouch = [self.layer convertPoint:pointOfTouch toLayer:hostedGraph];
}
else {
pointOfTouch.y = self.frame.size.height - pointOfTouch.y;
}
[hostedGraph pointingDeviceDownEvent:event atPoint:pointOfTouch];
[self.nextResponder touchesBegan:touches withEvent:event]; //-------将touch事件继续向下传递
}
chat 需要显示再对应的view上,我们需要获得touch事件,因此自定义view 拦截touch
@implementation UIViewInterceptGuest
@synthesize viewsToControl;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self disableScrollEnabled];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self enableScrollEnabled];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[self enableScrollEnabled];
}
-(void)disableScrollEnabled{
for (UIScrollView* v in viewsToControl) {
v.scrollEnabled=NO;
}
}
-(void)enableScrollEnabled{
for (UIScrollView* v in viewsToControl) {
v.scrollEnabled = YES;
}
}
@end