No Swift, como você escreveria o método scrollViewWillEndDragging withVelocity targetContentOffset?
Como alguém escreveria isso emRápido?
Atualizar: postou o método que estou tentando converter, originalmente postou um método diferente que não era o que eu estava tentando ocultar
Isso funciona no objetivo C, mas não no Swift. Eu recebo erros de conversão quando tento usarceilf
efloorf
comCGFloat
.
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
float pageWidth = 200 + 30; // width + space
float currentOffset = scrollView.contentOffset.x;
float targetOffset = targetContentOffset->x;
float newTargetOffset = 0;
if (targetOffset > currentOffset)
newTargetOffset = ceilf(currentOffset / pageWidth) * pageWidth;
else
newTargetOffset = floorf(currentOffset / pageWidth) * pageWidth;
if (newTargetOffset < 0)
newTargetOffset = 0;
else if (newTargetOffset > scrollView.contentSize.width)
newTargetOffset = scrollView.contentSize.width;
targetContentOffset->x = currentOffset;
[scrollView setContentOffset:CGPointMake(newTargetOffset, 0) animated:YES];
}