我是iOS编程的初学者,很抱歉,如果我的问题是一个愚蠢的问题.
我正在尝试制作一个在加载的图像上执行自定义绘图的应用程序.
为此,我发现解决方案是子类化UIView和编辑drawRect方法.
我在以下代码上创建了该代码,该代码IBAction在Interface Builder故事板文件中链接到按钮时激活.
UIImageView *image = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"SampleImage.jpg"]];
image.frame = previewView.frame;
[image setContentMode:UIViewContentModeScaleAspectFit];
[previewView addSubview:image];
customView *aCustomView = [[customView alloc] initWithFrame: CGRectMake(image.bounds.origin.x, image.bounds.origin.y, image.bounds.size.width, image.bounds.size.height)];
[previewView addSubview:aCustomView];
Run Code Online (Sandbox Code Playgroud)
customView是UIView我创建的子类,其init和drawRect方法设置如下:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
NSLog(@"INITIALIZING");
if (self) {
// Initialization code
[self setBackgroundColor:[UIColor clearColor]];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
NSLog(@"DRAWING");
CGContextClearRect(ctx, rect);
CGContextSetRGBFillColor(ctx, 0, …Run Code Online (Sandbox Code Playgroud) 我正在开发一个跟踪用户在后台位置的应用程序,并不时将该位置发送到后端.我有兴趣监控日常使用对电池的影响,包括:
我认为仪器能量记录和位置能量模型非常适合跟踪设备能耗,我想设置几个小时的无线跟踪会话.我已经设置了一个分析模板,它可以在插入我的Mac时正确跟踪手机的数据,但我无法打开无线分析模式!
此外,我想知道这是否是正确的方法,让我的应用程序"观察"几个小时,然后下载跟踪数据并在会话结束时进行分析.
iPhone型号是5s.iOS版本是10.3.2
我做得对吗?我错过了配置无线分析的任何步骤(我遵循Apple文档关于无线分析)