这基本上是我希望它表现的方式:
在顶部应该有一个UIbutton(或类似的),允许用户在展开和折叠之间切换.
展开后,我希望能够放置其他UIVIEw(例如日历),当折叠时,周围的控件应该向上移动.
有没有人有任何想法如何实现这简单 – noob在这里:(
解决方法 对VIEwController进行子类化,并且有两个方法,按钮可以像’collapse’和’expand’一样触发,这可能会让你开始:你可以动态地为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 }}总结
以上是内存溢出为你收集整理的iphone – 如何创建可折叠的UIView全部内容,希望文章能够帮你解决iphone – 如何创建可折叠的UIView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)