StackView
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
의 데이터 원본을 정의했는데 이것은 UITableView
와 UICollectionView
와 같다.(아직 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
제스처가 끝날 때 애니메이션의 복원 또는 변화를 판단하고 사용@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
에 대해 스스로 정의할 수 있고 더 좋은 중첩 효과를 낼 수 있습니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.