2012-12-29 12 views

Odpowiedz

20

Musisz samodzielnie zmienić contentOffset swojej UITableView. Pamiętaj, aby uwzględnić numer contentInset.top. Powinno to być coś tak prostego jak:

CGPoint newOffset = CGPointMake(0, -[myTableView contentInset].top); 
[myTableView setContentOffset:newOffset animated:YES]; 
+3

I” ve zauważyłem, że to powoduje problemy z rysowaniem komórek, jeśli nie zresetujesz również contentOffset po wywołaniu 'endRefreshing':' [myTableView setContentOffset: CGPointZero animowane: TAK]; ' –

+4

Nie działają w iOS8 – AlKozin

+2

Nie działa w ios 9. – cdub

17

będzie to rade

- (void)beginRefreshingTableView { 

    [self.refreshControl beginRefreshing]; 

    // check if contentOffset is zero 
    if (fabsf(self.tableView.contentOffset.y) < FLT_EPSILON) { 

     [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^(void){ 

      self.tableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height); 

     } completion:^(BOOL finished){ 

     }]; 

    } 
} 
+1

Najwyraźniej musisz wywołać 'beginRefreshing' wewnątrz bloku zakończenia animacji tableview lub po wywołaniu animacji, w przeciwnym razie tintColor ustawionego przez ciebie refreshControl zostanie zignorowany. http://stackoverflow.com/a/20383030/903544 –

8

Dla Swift 3, to co mam na podstawie Petera Lapisu za odpowiedź:

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.refreshControl?.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged) 
    // ... 
} 

func refresh(sender:AnyObject) { 
    self.refreshControl?.beginRefreshing() 

    if let yOffsetTable = self.tableView?.contentOffset.y { 
     if yOffsetTable < CGFloat(Float.ulpOfOne) { 
      UIView.animate(withDuration: 0.25, delay: 0, options: UIViewAnimationOptions.beginFromCurrentState, animations: { 
       if let refreshControlHeight = self.refreshControl?.frame.height { 
        self.tableView?.contentOffset = CGPoint(x: 0, y: -refreshControlHeight) 
       } 
      }, completion: nil) 
     } 
    } 
} 
Powiązane problemy