我正在使用CorePlot在我的macOS应用程序中绘制一个简单的线图.
CPTXYGraph *newGraph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
[newGraph applyTheme:theme];
self.graph = newGraph;
self.hostView.hostedGraph = newGraph;
newGraph.plotAreaFrame.paddingTop = 10.0;
newGraph.plotAreaFrame.paddingBottom = 30.0;
newGraph.plotAreaFrame.paddingLeft = 40.0;
newGraph.plotAreaFrame.paddingRight = 10.0;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)newGraph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:@(1.0) length:[NSNumber numberWithUnsignedInteger:[dataArray count]-1]];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:@0.0 length:@102.0];
plotSpace.allowsUserInteraction = YES;
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)newGraph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
//x.majorIntervalLength = @1;
x.majorIntervalLength = [NSNumber numberWithInt:numberOfIntervalsX];
x.orthogonalPosition = @(0);
x.minorTicksPerInterval = 0;
x.labelOffset = 0;
CPTXYAxis *y = …Run Code Online (Sandbox Code Playgroud) 嗨我使用下面的代码片段来获取给定类中触摸的X和Y坐标以及ViewController的名称:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
NSLog(@"Began: %@ X location: %0.2f", NSStringFromClass([self class]), point.x);
NSLog(@"Began: %@ Y location: %0.2f", NSStringFromClass([self class]), point.y);
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
NSLog(@"Ended:%@ X location: %0.2f", NSStringFromClass([self class]), point.x);
NSLog(@"Ended:%@ Y Location: %0.2f", NSStringFromClass([self class]), point.y);
}
Run Code Online (Sandbox Code Playgroud)
最初我只想为两个ViewControllers做这件事,但现在我想为所有类做这件事.我是否必须在每个类中编写这些片段以满足需要或者我可以使用单例实例?
这是我的Singleton类代码:
QuestionAlert.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface QuestionAlert : NSObject
+(id)sharedManager;
@end
QuestionAlert.m
#import "QuestionAlert.h" …Run Code Online (Sandbox Code Playgroud)