2016-06-12 60 views
0

裏面添加UIPagerControl我的tableView的細胞內,我有一個ImageView的還有我想插入UIPageControll,這樣我可以在我的ImageView通過像這樣添加多張圖片和滾動:一個UITableViewCell的ImageView的

enter image description here

這就是我試圖(和卡住了):

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的手勢和我也能調用這個功能,但是現在怎麼是一天要改變這個形象?任何線索或指導將是我這樣的幫助

私人祕書,如果我的問題不夠清楚,那麼請讓我知道我會添加一些細節

+0

你想要用戶只需滑動的imagView對象。對? –

+0

是的,改變圖像滑動@NiravDoctorwala –

+0

在你的手勢方法裏寫這個let imageVIew = gesture.view as! UIImageView –

回答

3

在您cellForRowAt指數添加此代碼

cell.imgView.userInteractionEnable = true 
cell.imgView.addGestureRecognizer(self.swipeGestureLeft) 
cell.imgView.addGestureRecognizer(self.swipeGestureRight) 

希望這會幫助你。

+0

以及它做我所要求的,但並不像預期的那樣改變圖像的毛刺(突然)效果,我不得不使用UIPageControllers,順便說一句,謝謝,感謝你的努力 –

相關問題