사용하여 안드로이드 접근 방식에 대한 링크. 이 모든 것은 배너 뷰 객체 안에 포함될 수 있습니다. frame
속성은 애니메이션 가능합니다.
BannerView를 UIView의 하위 클래스로 만듭니다. 그것은 공공 @interface
의에 몇 가지 방법을 추가
@property (nonatomic, assign) CGRect expandedFrame;
@property (nonatomic, assign) CGRect collapsedFrame;
이가 (공개) @interface이나 갈 수
- (void) collapse;
- (void) expand;
- (void) toggle;
당신은 배너의 확장하거나 축소 프레임에 대한 몇 가지 속성을 원할 것입니다 (개인) 카테고리 확장. 당신이 확장하거나 bannerView을 축소 할 때마다 그들의 각각을 설정하여 그에 따라 위나 아래로 이동하거나 반복 양식
for (UIView* view in self.superview.subviews) {}
를 사용하여 뷰를 형제를 통해
//initialising in code
- (id)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self initialiseFrames:frame];
}
return self;
}
//initialising from XIB/Storyboard
- (void)awakeFromNib {
[self initialiseFrames:self.frame];
}
- (void)initialiseFrames:(CGRect)frame {
self.expandedFrame = frame;
frame.size.height = 0;
self.collapsedFrame = frame;
}
, 그것은 반복 할 수 다음 BannerView의 초기화 과정을 설정 frame
속성 함께 그 조각을 퍼팅 ... 추가하거나 bannerView의 높이를 빼기,
- (CGRect)lowerFrame:(CGRect)frame {
frame.origin.y += CGRectGetHeight(self.expandedFrame);
return frame;
}
- (CGRect)raiseFrame:(CGRect)frame {
frame.origin.y -= CGRectGetHeight(self.expandedFrame);
return frame;
}
을 높이고 낮은 프레임, 당신은 붕괴하고 자신의 프레임을 설정하여 올바른받은 위치에 형제 뷰를 이동 애니메이션의 방법을 확장하고 축소 할 수 있습니다 /이 프레임의 을 설정하여 배너보기를 확장 :
- (void) collapse {
if (CGRectEqualToRect(self.frame, self.collapsedFrame)) return;
[UIView animateWithDuration:0.5 animations:^{
for (UIView* view in self.superview.subviews) {
if (CGRectGetMinY(view.frame) > CGRectGetMaxY(self.frame))
view.frame = [self raiseFrame:view.frame];
}
self.frame = self.collapsedFrame;
}];
}
- (void) expand {
if (CGRectEqualToRect(self.frame, self.expandedFrame)) return;
[UIView animateWithDuration:0.5 animations:^{
for (UIView* view in self.superview.subviews) {
if (CGRectGetMinY(view.frame) > CGRectGetMaxY(self.frame))
view.frame = [self lowerFrame:view.frame];
}
self.frame = self.expandedFrame;
}];
}
... 그리고 두 상태 사이를 이동하는 전환 방법
- (void) toggle {
if (CGRectEqualToRect(self.frame, self.collapsedFrame))
[self expand];
else [self collapseBanner];
}