StackView

4701 단어

StackView


기분이 별로 좋지 않고 코드를 쓸 흥미도 별로 없다.전에 쓴 코드를 아무렇게나 가지고 작은 설명을 하다.

Reason


최근에 접어 놓은 View 용기를 사용해야 할 수도 있지만 인터넷에 아주 적합한 구성 요소가 없는 것 같습니다. (제가 깊이 파지 않았을 수도 있습니다.) 전에 제 동료가 이런 구성 요소를 만들었지만 발표하지 않았습니다. 실현된 원본 코드를 보고 변경을 해서 구성 요소를 만들어Pod에 발표했습니다.

방법


이 용기는 내가 다시View로 썼고, 비교적 서투르게 썼다. 만약 좋은 변동이 있다면, 포크가 Github에 있는 코드를 환영하고,pull request를 제출하십시오.부정할 수 없는 것은 이것이 틀림없이 사용자 정의 Collection View Layout을 통해 이루어질 것이다. 장래에는 Collection View Layout으로 이루어진 코드를 가져올 수도 있고 Swift 버전을 실현할 수도 있다. 또한 여러분들이 코드를 써주시고pull request를 올려주시는 것을 환영합니다.그럼 코드를 한번 봅시다.
/**
 * It's a property save cells and handle cell actions
 *
 */
@property (nonatomic, strong) StackViewDefaultPile *pile;

/**
 * The components datasource
 *
 */
@property (nonatomic, weak) id datasource;

/**
 * Reload data clear all cell and readd cells into component
 *
 */
- (void)reloadData;

/**
 * Get Cell with Reuseid
 *
 */
- (UIView *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index;

/**
 * regist cell with nibname and id
 *
 */
- (void)registerCellWithNibName:(NSString *)nibName forCellReuseIdentifier:(NSString *)identifier;


속성 보기
  • @property (nonatomic, strong) StackViewDefaultPile *pile는 하나의 StackViewDefaultPile 유형의 속성을 정의했다. 이쪽은 내가 쓴 방식이고 지금은 바뀌어야 한다. 이것은 관리 구성 요소 내부의View 더미이다. 다음 코드에서 나는 StackViewPile의 공공 인터페이스를 분리했다. BaseStackViewPie를 정의했고 사용자는 사용자 정의StackViewPile를 할 수 있다. StackViewDefaultPile와 같이 BaseStackViewPie의 인터페이스를 실현하면 된다.
  • @property (nonatomic, weak) id datasource;StackViewComponent의 데이터 원본을 정의했는데 이것은 UITableViewUICollectionView와 같다.(아직 delegate를 붙이지 않았다) 장래에 틈이 나면 더할 것이다.

  • 방법(거의 표준 UItableView 및 UICollectionView로 설계됨)
  • - (void)reloadData;는 이 구성 요소의 데이터를 다시 읽고 렌더링합니다.
  • - (UIView *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index; 다시 사용한 id로 등록된View의 대상을 획득
  • registerCellWithNibName:(NSString *)nibName forCellReuseIdentifier:(NSString *)identifier; id와 자원 파일 이름을 다시 사용하여View에 등록한 대상
  • StackViewDatasource
  • - (UIView *)stackView:(StackViewComponent *)stackView cellForIndex:(NSInteger)index index를 통해 현재 View의 대상을 되돌려줍니다.
  • - (CGSize)stackViewCellSize:(StackViewComponent *)stackView 각 View의 크기
  • 를 반환합니다.
  • - (NSInteger)stackViewNumberOfRow:(StackViewComponent *)stackView 총 View 개수
  • 로 반환
    구현 파일
  • - (void)awakeFromNib부끄럽습니다.xib에서 이 구성 요소를 불러오는 데만 적용됩니다.따라서 초기화 작업은 거의 모두 - (void)awakeFromNib에 놓여 있고 - (void)awakeFromNib에는 모두 두 가지 절차가 포함되어 있다. 각각 내부 속성을 초기화하고 Views를 초기화하는 것이다
  • - (void)setDatasource:(id)datasource데이터소스가 바뀔 때reloadData
  • - (void)reloadData는 두 단계로 나뉘어 모든 View를 제거하고 pile를 리셋한 다음에 모든 pile의 View
  • 를 다시 렌더링합니다.
  • - (void)panGestureDidBegin:(UIPanGestureRecognizer *)gesture 제스처를 시작할 때 현재 위치를 기록
  • - (void)panGestureDidMove:(UIPanGestureRecognizer *)gesture 제스처 이동 위치에 따라 pile
  • 조정
  • - (void)panGestureDidEnd:(UIPanGestureRecognizer *)gesture 제스처가 끝날 때 애니메이션의 복원 또는 변화를 판단하고 사용
  • pile
    @property (nonatomic, strong) NSArray *alphaArray;
    @property (nonatomic, strong) NSArray *zTransformArray;
    @property (nonatomic, assign) CGFloat rangeLength;
    @property (nonatomic, strong) UIView *previousCell;
    @property (nonatomic, strong) UIView *nextCell;
    @property (nonatomic, assign) CATransform3D cellTransform;
    
    - (void)reset;
    - (void)recover;
    - (void)pushNextCell;
    - (void)pushPreviousCell;
    - (UIView *)cellOfIndex:(NSInteger)index;
    - (void)setCell:(UIView *)cell atIndex:(NSInteger)index;
    - (UIView *)removeCellAtIndex:(NSInteger)index;
    - (UIView *)bringPreviousCellToTop;
    - (UIView *)bringNextCellToBottom;
    - (NSInteger)maxSize;
    - (void)resetCell:(UIView *)cell atIndex:(NSInteger)index;
    - (void)updateCellWithOffset:(CGFloat)offset;
    

    이 코드들은 설명을 많이 하지 않겠습니다. Pile을 사용자 정의하려면 StackViewDefaultPile처럼 - (NSInteger)maxSize,- (void)reset,- (UIView *)cellOfIndex:(NSInteger)index,- (void)setCell:(UIView *)cell atIndex:(NSInteger)index 방법을 정의하고 몇 개의 View를 정의하면 일부 속성alphaArray,zTransformArray,rangeLength에 대해 스스로 정의할 수 있고 더 좋은 중첩 효과를 낼 수 있습니다.

    좋은 웹페이지 즐겨찾기