我是iOS开发的新手,请关注我的问题。
正如我的标题所说,
如何将UIView
( with Animation )隐藏并显示为UIActionSheet
?
在谷歌搜索,芽没有找到有效的解决方案..
答案 0 :(得分:7)
请尝试以下代码:
- (IBAction)showTapped:(id)sender {
hideButton.enabled=YES;
showButton.enabled=NO;
[UIView animateWithDuration:.5 animations:^{
subView.frame=CGRectMake(0, 225, subView.frame.size.width, subView.frame.size.height);
}];
}
- (IBAction)hideTapped:(id)sender {
hideButton.enabled=NO;
showButton.enabled=YES;
[UIView animateWithDuration:.5 animations:^{
subView.frame=CGRectMake(0, 480, subView.frame.size.width, subView.frame.size.height);
}];
}
答案 1 :(得分:4)
在这种情况下,您可以做的是在窗口上添加UIView
,然后在需要时显示它。所以,首先你需要创建一个AppDelegate
的对象。
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
创建您的视图
CGRect frame = CGRectMake(0, 460, 320, 300);
UIView *ActionView = [UIView alloc]initWithFrame:frame];
这是为了在窗口上显示您的视图,请注意您的视图的 y坐标应低于屏幕尺寸,以便您可以将其恢复到某个级别,然后发送它再次下降。
[appDelegate.window addSubview:ActionView];
然后只需添加这些自定义动画即可显示和隐藏您的视图
揭示你的观点
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.25];
CGRect rect = [ActionView frame];
rect.origin.y = -300;
[ActionView setFrame:rect];
[UIView commitAnimations];
隐藏您的视图
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.25];
CGRect rect = [ScrollView frame];
rect.origin.y = 460;
[ScrollView setFrame:rect];
[UIView commitAnimations];
最后,您可以根据自己的尺寸和框架进行调整。希望这会有所帮助...
答案 2 :(得分:0)
试试这个解决方案....它有效
#pragma mark - Date Selector View PresentModelView with Transparent ViewController
- (void) showModal:(UIView*) modalView {
UIWindow *mainWindow = [(AppDelegate *)[UIApplication sharedApplication].delegate window];
CGPoint middleCenter;
middleCenter = CGPointMake(modalView.center.x, modalView.center.y);
CGSize offSize = [UIScreen mainScreen].bounds.size;
CGPoint offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.5);
modalView.center = offScreenCenter;
if ([[mainWindow subviews] containsObject:modalView]) {
[modalView removeFromSuperview];
}
[mainWindow addSubview:modalView];
[mainWindow bringSubviewToFront:modalView];
// Show it with a transition effect
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
// animation duration in seconds
modalView.center = middleCenter;
[UIView commitAnimations];
}
// Use this to slide the semi-modal view back down.
- (void) hideModal:(UIView*) modalView {
CGSize offSize = [UIScreen mainScreen].bounds.size;
CGPoint offScreenCenter = CGPointMake(offSize.width / 2.0, offSize.height * 1.5);
[UIView beginAnimations:nil context:(__bridge void *)(modalView)];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(hideModalEnded:finished:context:)];
modalView.center = offScreenCenter;
[UIView commitAnimations];
}
- (void) hideModalEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
UIView *modalView = (__bridge UIView *)context;
[modalView removeFromSuperview];
}