Простой ответ на этот вопрос ... используйте UIScrollView
.
От моего вопроса здесь ... Loop UIScrollView but continue decelerating
Переводя его Swift тривиальна, но здесь идет ...
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//make the content size really big so that the targetOffset of the deceleration will never be met.
scrollView.contentSize = CGSize(width: CGRectGetWidth(scrollView.frame) * 100.0, height: CGRectGetHeight(scrollView.frame))
//set the contentOffset of the scroll view to a point in the center of the contentSize.
scrollView.setContentOffset(CGPoint(CGRectGetWidth(scrollView.frame) * 50, 0), animated: false)
}
func rotateImageView() {
//Calculate the percentage of one "frame" that is the current offset.
// each percentage of a "frame" equates to a percentage of 2 PI Rads to rotate
let minOffset = CGRectGetWidth(scrollView.frame) * 50.0
let maxOffset = CGRectGetWidth(scrollView.frame) * 51.0
let offsetDiff = maxOffset - minOffset
let currentOffset = scrollView.contentOffset.x - minOffset
let percentage = currentOffset/offsetDiff
arrowView.transform = CGAffineTransformMakeRotation(M_PI * 2 * percentage)
}
func scrollViewDidScroll(scrollView: UIScrollView) {
//the scrollView moved so update the rotation of the image
rotateImageView()
}
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
//the scrollview stopped moving.
//set the content offset back to be in the middle
//but make sure to keep the percentage (used above) the same
//this ensures the arrow is pointing in the same direction as it ended decelerating
let diffOffset = scrollView.contentOffset.x
while diffOffset >= CGRectGetWidth(scrollView.frame) {
diffOffset = diffOffset - CGRectGetWidth(scrollView.frame)
}
scrollView.setContentOffset(CGPoint(x: CGRectGetWidth(scrollView.frame) * 50 + diffOffset, y: 0), animated:false)
}
В этом примере мой взгляд прядения является arrowView
. scrollView
и arrowView
должны быть одновременно рассмотрены в представлении контроллера. scrollView
не должен иметь ничего в этом.
N.B. Это делается в браузере, поэтому могут возникнуть проблемы с синтаксисом. Возможно, вам также придется отдать некоторые цифры CGFloat
и т. Д.
Кроме того, возможность перевода с Objective-C необходима для любого разработчика iOS. Миллионы приложений написаны с использованием Objective-C. Синтаксис может немного отличаться, но все API-интерфейсы одинаковы.
Обучение тому, что должно делать каждый iOS-разработчик.
Просто интересно, увидели ли вы мое редактирование на мой ответ. Теперь он включает в себя весь быстрый код, чтобы это можно было сделать. – Fogmeister
Вы, кажется, позаботились об этом. Just6 проверяет, есть ли у вас работа? Спасибо – Fogmeister