小编fig*_*ump的帖子

如何从当前图形上下文创建UIImage?

我想从当前的图形上下文创建一个UIImage对象.更具体地说,我的用例是用户可以绘制线条的视图.他们可以逐步绘制.完成后,我想创建一个UIImage来代表他们的绘图.

这是drawRect:现在对我来说是这样的:

- (void)drawRect:(CGRect)rect
{
CGContextRef c = UIGraphicsGetCurrentContext();

CGContextSaveGState(c);
CGContextSetStrokeColorWithColor(c, [UIColor blackColor].CGColor);
CGContextSetLineWidth(c,1.5f);

for(CFIndex i = 0; i < CFArrayGetCount(_pathArray); i++)
{
    CGPathRef path = CFArrayGetValueAtIndex(_pathArray, i);
    CGContextAddPath(c, path);
}

CGContextStrokePath(c);

CGContextRestoreGState(c);
}
Run Code Online (Sandbox Code Playgroud)

...其中_pathArray的类型为CFArrayRef,并且每次调用touchesEnded:时都会填充.另请注意,drawRect:可以在用户绘制时多次调用.

用户完成后,我想创建一个表示图形上下文的UIImage对象.有关如何做到这一点的任何建议?

core-graphics quartz-graphics uiimage ios

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

使用 HKHeartbeatSeriesSample 来自 Apple Watch 的实时心跳数据

我正在尝试实时访问 Apple Watch 记录的心跳数据。通过 HKWorkoutSession,我可以每 5 秒回调一次workoutBuilder didCollectDataOf心率(心跳/分钟)数据。

\n\n

这对于我的应用程序来说不够实时,因此我正在考虑使用新的(从 iOS 13 和 watchOS 6.0 开始)HKHeartbeatSeriesSample(和相关类)来实现此目的。我的理解是,心跳数据的系列样本将以系列形式记录逐次心跳的测量结果。

\n\n

我能够让 API 工作并获取一些数据,但不是实时的——我获取的系列数据来自以前的一些记录(不清楚是什么触发了这些记录)。

\n\n

这里是授权:

\n\n
            let allTypes: Set<HKSampleType> = Set([\n                HKObjectType.workoutType(),\n                HKSeriesType.heartbeat(),\n                HKObjectType.quantityType(forIdentifier: .heartRate)!,\n                HKQuantityType.quantityType(forIdentifier: .heartRateVariabilitySDNN)!,\n            ])\n\n            healthStore.requestAuthorization(toShare: allTypes, read: allTypes) { (success, error) in\n                ///...\n                let workoutSession = WorkoutSession(healthStore: self.healthStore)\n                workoutSession.startHeartbeatSampleQuery()\n            }\n\n
Run Code Online (Sandbox Code Playgroud)\n\n

startHeartBeatSampleQuery:

\n\n
            let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierStartDate,\n                                                  ascending: false)\n\n            // Query for the heartbeat samples from the specified heartbeat series.\n            let heartbeatSeriesSampleQuery = HKSampleQuery(sampleType: HKSeriesType.heartbeat(),\n …
Run Code Online (Sandbox Code Playgroud)

ios swift healthkit apple-watch watchkit

4
推荐指数
1
解决办法
4306
查看次数