我需要创建一个可扩展和可折叠的某种UIView,并且无法支付第三方控件。如何创建一个可折叠的UIView
这基本上是我怎么想它的行为:
在顶部应该有一个UIButton(或类似),允许用户切换之间展开和折叠。
展开后,我希望能够放置其他UIView(例如日历),并且在折叠时周围的控件应该向上移动。
没有人有任何想法如何实现这个简单 - 小白这里:(
我需要创建一个可扩展和可折叠的某种UIView,并且无法支付第三方控件。如何创建一个可折叠的UIView
这基本上是我怎么想它的行为:
在顶部应该有一个UIButton(或类似),允许用户切换之间展开和折叠。
展开后,我希望能够放置其他UIView(例如日历),并且在折叠时周围的控件应该向上移动。
没有人有任何想法如何实现这个简单 - 小白这里:(
子类视图控制器,并有两种方法,你的按钮就可以火象“崩溃”和“扩大”,这可能让你开始:您可以动态地分配新的选择,以UIButtons:
[button addTarget:self action:@selector(eventMethod:)
forControlEvents:UIControlEventTouchUpInside];
代码:
#define COLAPSED_HEIGHT 30
-(void)expand
{
CGRect s= [self getScrerenBoundsForCurrentOriantation];
CGRect f = self.view.frame;
f.origin.y =s.size.height-self.view.frame.size.height;
[UIView beginAnimations:@"expand" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
self.view.frame=f;
//CHANGE YOUR EXPAND/COLLAPSE BUTTON HERE
[UIView commitAnimations];
self.thumbScrollerIsExpanded=YES;
}
-(void)collapseView
{
//re-factored so that this method can be called in ViewdidLoad
CGRect s= [self getScrerenBoundsForCurrentOriantation];
CGRect f = self.view.frame;
f.origin.y =(s.size.height-COLAPSED_HEIGHT);
self.view.frame = f;
self.thumbScrollerIsExpanded=NO; //thumbScrollerIsExpanded is a BOOL property
}
- (void)collapse
{
[UIView beginAnimations:@"collapse" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
[self collapseView];
//CHANGE YOUR EXPAND/COLLAPSE BUTTON HERE
[UIView commitAnimations];
}
-(CGRect)getScrerenBoundsForCurrentOriantation
{
return [self getScrerenBoundsForOriantation:[[UIDevice currentDevice] orientation]];
}
-(CGRect)getScrerenBoundsForOriantation:(UIInterfaceOrientation)_orientation
{
UIScreen *screen = [UIScreen mainScreen];
CGRect fullScreenRect = screen.bounds; // always implicitly in Portrait orientation.
if (UIInterfaceOrientationIsLandscape(_orientation))
{
CGRect temp;
temp.size.width = fullScreenRect.size.height;
temp.size.height = fullScreenRect.size.width;
fullScreenRect = temp;
}
return fullScreenRect;
}
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
if ([animationID isEqualToString:@"expand"])
{
//example
}
else if ([animationID isEqualToString:@"collapse"])
{
//example
}
}
你可以尝试添加一个UIView(无论是在厦门国际银行或程序)关闭屏幕een,然后使用UIView动画将其滑入您的主查看区域。
该按钮将有一个IBAction,它将切换动画(滑入/滑出)。你可以将它滑出屏幕,然后将UIView的隐藏属性设置为true。当您回想起IBAction时,请检查视图的隐藏属性是否为真。如果是的话,你知道要播放它的动画,如果没有,那么你就播放滑出的动画。