裏面添加UIPagerControl我的tableView的細胞內,我有一個ImageView的還有我想插入UIPageControll,這樣我可以在我的ImageView通過像這樣添加多張圖片和滾動:一個UITableViewCell的ImageView的
這就是我試圖(和卡住了):
tableViewCell:
class EventsTableViewCell: UITableViewCell {
@IBOutlet var coverView: UIView!
@IBOutlet var pageController: UIPageControl!
@IBOutlet var imgView: UIImageView!
let swipeGestureLeft = UISwipeGestureRecognizer()
let swipeGestureRight = UISwipeGestureRecognizer()
...................... ...........
...........
}
的TableView:
///// inside cellforRowAtIndexPath
........
PagerController = cell.pageController
swipeGestureLeft = cell.swipeGestureLeft
swipeGestureRight = cell.swipeGestureRight
coverView = cell.coverView
// set gesture direction
self.swipeGestureLeft.direction = UISwipeGestureRecognizerDirection.Left
self.swipeGestureRight.direction = UISwipeGestureRecognizerDirection.Right
// add gesture in to view
coverView.addGestureRecognizer(self.swipeGestureLeft)
coverView.addGestureRecognizer(self.swipeGestureRight)
// add gesture target
self.swipeGestureLeft.addTarget(self, action: #selector(self.handleSwipeLeft(_:)))
self.swipeGestureRight.addTarget(self, action: #selector(self.handleSwipeRight(_:)))
.
.
.
.
.
.
// functions for recognising the Gestures
func handleSwipeLeft(gesture: UISwipeGestureRecognizer){
if self.PagerController.currentPage != 2 {
print("left :\(self.PagerController.currentPage) ")
self.PagerController.currentPage += 1
imgView.image = UIImage(named: "cover\(self.PagerController.currentPage)")
}
}
//
func handleSwipeRight(gesture: UISwipeGestureRecognizer){
if self.PagerController.currentPage != 0 {
print("right :\(self.PagerController.currentPage)")
imgView.image = UIImage(named: "cover\(self.PagerController.currentPage)")
self.PagerController.currentPage -= 1
}
}
你可以看到,我能夠認出了我的coverView
這是一個UIView的覆蓋ImageView的手勢和我也能調用這個功能,但是現在怎麼是一天要改變這個形象?任何線索或指導將是我這樣的幫助
私人祕書,如果我的問題不夠清楚,那麼請讓我知道我會添加一些細節
你想要用戶只需滑動的imagView對象。對? –
是的,改變圖像滑動@NiravDoctorwala –
在你的手勢方法裏寫這個let imageVIew = gesture.view as! UIImageView –