UICollectionViewController에서 당겨서 새로 고침
UICollectionViewController
iOS 6 에서 풀다운에서 새로 고침을 구현하고 싶습니다 . 이것은 UITableViewController
다음과 같이를 사용하여 쉽게 달성 할 수있었습니다 .
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(startRefresh:)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
위의 내용은 네이티브 위젯의 일부로 멋진 액체 방울 애니메이션을 구현합니다.
UICollectionViewController
"더 발전된" 것처럼 UITableViewController
기능의 패리티를 어느 정도 기대할 수 있지만이를 구현하는 기본 제공 방법에 대한 참조는 어디에서도 찾을 수 없습니다.
- 내가 간과하는 간단한 방법이 있습니까?
- 헤더와 문서가 모두 테이블 뷰와 함께 사용하도록
UIRefreshControl
되어UICollectionViewController
있음에도 불구하고 어떻게 든 사용할 수 있습니까 ?
(1)과 (2) 모두 그렇습니다.
UIRefreshControl
인스턴스를의 하위보기로 추가하기 만하면 .collectionView
작동합니다.
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(startRefresh:)
forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];
그게 다야! 때로는 간단한 실험이 트릭을 수행하더라도 이것이 문서 어딘가에 언급 되었기를 바랍니다.
편집 :이 솔루션은 컬렉션이 활성 스크롤바를 가질만큼 충분히 크지 않은 경우 작동하지 않습니다. 이 문장을 추가하면
self.collectionView.alwaysBounceVertical = YES;
그러면 모든 것이 완벽하게 작동합니다. 이 수정 사항 은 동일한 주제에 대한 다른 게시물 에서 가져온 것입니다 (다른 게시 된 답변의 댓글에서 참조 됨).
나는 같은 해결책을 찾고 있었지만 Swift에서. 위의 답변을 바탕으로 다음을 수행했습니다.
let refreshCtrl = UIRefreshControl()
...
refreshCtrl.addTarget(self, action: "startRefresh", forControlEvents: .ValueChanged)
collectionView?.addSubview(refreshCtrl)
잊지 마세요 :
refreshCtrl.endRefreshing()
스토리 보드를 사용하고 있었는데 설정 self.collectionView.alwaysBounceVertical = YES;
이 작동하지 않았습니다. 을 선택 Bounces
하고 Bounces Vertically
나를 위해 일을한다.
이제 refreshControl
속성이 UIScrollView
iOS 10 부터 추가 되었으므로 컬렉션보기에서 직접 새로 고침 제어를 설정할 수 있습니다.
https://developer.apple.com/reference/uikit/uiscrollview/2127691-refreshcontrol
UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:@selector(refreshControlAction:) forControlEvents:UIControlEventValueChanged];
self.collectionView.refreshControl = refreshControl;
mjh의 대답이 맞습니다.
collectionView.contentSize
이보다 크지 않은 경우 스크롤 collectionView.frame.size
할 수없는 문제가 발생 collectionView
했습니다. contentSize
속성을 설정할 수 없습니다 (적어도 나는 할 수 없었습니다).
스크롤 할 수없는 경우 당겨서 새로 고침 할 수 없습니다.
내 해결책은 UICollectionViewFlowLayout
메서드 를 하위 클래스로 만들고 재정의하는 것입니다.
- (CGSize)collectionViewContentSize
{
CGFloat height = [super collectionViewContentSize].height;
// Always returns a contentSize larger then frame so it can scroll and UIRefreshControl will work
if (height < self.collectionView.bounds.size.height) {
height = self.collectionView.bounds.size.height + 1;
}
return CGSizeMake([super collectionViewContentSize].width, height);
}
참고 URL : https://stackoverflow.com/questions/13085662/pull-to-refresh-in-uicollectionviewcontroller
'Nice programing' 카테고리의 다른 글
Xcode 6 및 10.10 Yosemite가 포함 된 Cocoapods (0) | 2020.10.22 |
---|---|
컨텐츠 편집 가능한 엔티티의 끝으로 커서를 이동하는 방법 (0) | 2020.10.22 |
쉼표로 구분 된 쉘 변수를 통해 루프 (0) | 2020.10.22 |
Chrome DevTools를 열 때마다 기본적으로 "콘솔 드로어"를 숨기려면 어떻게해야합니까? (0) | 2020.10.22 |
Htaccess : URL에서 후행 슬래시 추가 / 제거 (0) | 2020.10.22 |