Tag: 进步

通过添加删除控制进度儿童

默认情况下,控制Progress子级仅使将子级添加到Progress实例变得容易,而默认情况下则无法删除。 当您要使用一个随时间推移具有不同子级的Progress实例时,这可能会很有用。 使用自定义类MutableProgress使这成为可能。 通过将进度子类化来控制进度儿童 自Swift 3.0起, NSProgress实例已重命名为Progress ,它是在Swift中用于进度报告的主要类。 通过我们自己管理孩子,我们可以控制孩子并增加删除孩子的可能性。 // Remove the Video upload progress, as the video file has been deleted by the user during upload. totalUploadProgress.removeChild(videoUploadProgress) 通过这样做,我们需要确保正确广播更新。 因此,我们需要覆盖属性fractionCompleted , totalUnitCount和completedUnitCount 。 Progress是在内部使用键值观察。 使用willChange和didChange可增加与willChange等UI元素的UIProgressView 。 /// Removes the given child from the progress reporting. /// /// – Parameter child: The child to remove. func […]