小编Dob*_*ode的帖子

UIView子类:未调用drawRect

我是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)

customViewUIView我创建的子类,其initdrawRect方法设置如下:

- (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)

objective-c uiview ios

14
推荐指数
2
解决办法
2万
查看次数

使用仪器进行iOS App无线分析:iPhone始终脱机

我正在开发一个跟踪用户在后台位置的应用程序,并不时将该位置发送到后端.我有兴趣监控日常使用对电池的影响,包括:

  • 用户不动
  • 用户从A走到B
  • 用户从A驾驶到B

我认为仪器能量记录和位置能量模型非常适合跟踪设备能耗,我想设置几个小时的无线跟踪会话.我已经设置了一个分析模板,它可以在插入我的Mac时正确跟踪手机的数据,但我无法打开无线分析模式!

我的手机一直处于脱机状态,无线配置. iPhone仅在插入时才在线. 无线配置文件始终处于脱机状态

此外,我想知道这是否是正确的方法,让我的应用程序"观察"几个小时,然后下载跟踪数据并在会话结束时进行分析.

iPhone型号是5s.iOS版本是10.3.2

我做得对吗?我错过了配置无线分析的任何步骤(我遵循Apple文档关于无线分析)

iphone xcode profiling background instruments

5
推荐指数
1
解决办法
1129
查看次数

标签 统计

background ×1

instruments ×1

ios ×1

iphone ×1

objective-c ×1

profiling ×1

uiview ×1

xcode ×1