Позвоните units
из duration
, чтобы получить единицу измерения и получить числовое значение путем поднабора duration
:
print(paste("Loop", i, "took", round(duration[[1]], 2), units(duration), "to run."))
Вот пример:
start_time <- Sys.time()
# few seconds later
end_time <- Sys.time()
duration <- difftime(end_time, start_time)
print(paste("Loop", 1, "took", round(duration[[1]], 2), units(duration), "to run."))
Результат :
[1] "Loop 1 took 6.97 secs to run."
Единица будет автоматической в зависимости от диапазона длительности. Смотрите этот другой пример:
start_time <- Sys.time()
# few days later
end_time <- as.Date("2019-01-23")
duration <- difftime(end_time, start_time)
print(paste("Loop", 1, "took", round(duration[[1]], 2), units(duration), "to run."))
Результат:
> print(paste("Loop", 1, "took", round(duration[[1]], 2), units(duration), "to run."))
[1] "Loop 1 took 5.9 days to run."
хорошо - ответил на мой собственный вопрос! скажем, у Вас есть набор CALayers в основном слое контроллера Вашего представления, и Вы хотите, чтобы они перешли к непрозрачности 0.5, когда Вы касаетесь их. реализуйте этот код в.m файле Вашего класса контроллера представления:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if ([touches count] == 1) {
for (UITouch *touch in touches) {
CGPoint point = [touch locationInView:[touch view]];
point = [[touch view] convertPoint:point toView:nil];
CALayer *layer = [(CALayer *)self.view.layer.presentationLayer hitTest:point];
layer = layer.modelLayer;
layer.opacity = 0.5;
}
}
}