我是 iOS 开发的新手,所以请注意我的问题。
正如我的标题所说,
我如何隐藏和显示UIView
(使用动画)UIActionSheet
?
在谷歌中搜索,bud 没有找到有效的解决方案..
我是 iOS 开发的新手,所以请注意我的问题。
正如我的标题所说,
我如何隐藏和显示UIView
(使用动画)UIActionSheet
?
在谷歌中搜索,bud 没有找到有效的解决方案..
试试下面的代码:
- (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);
}];
}
那么在这种情况下,您可以做的是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];
最后,您可以根据自己的尺寸和框架进行调整。希望这可以帮助...
试试这个解决方案....它有效
#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];
}
为此,请按照以下步骤操作:-
1)拖动UIView
命名为pickerView,添加到您的视图中。
2)拖动UIToolBar
(如果需要),添加到您的视图中。
3)拖动UIPickerView
,添加到您的视图中。
4)连接IBOutlet
到pickerView。
5)现在在您的代码中实现以下方法。
-(void)viewDidAppear:(BOOL)animated{
self.pickerView.frame = CGRectMake(0, self.view.frame.size.height+300, self.view.frame.size.width, 300);
}
-(void)hidePickerView{
self.isPickerHidden = YES;
[UIView animateWithDuration:0.5 animations:^{
self.pickerView.frame = CGRectMake(0, self.view.frame.size.height+300, self.view.frame.size.width, 300);
}];
}
-(void)showPickerView{
self.isPickerHidden = NO;
[UIView animateWithDuration:0.5 animations:^{
self.pickerView.frame = CGRectMake(0, self.view.frame.size.height-300, self.view.frame.size.width, 300);
}];
}
//Assuming you are tapping on cell, or you can use button connecting to the IBAction as well
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.isPickerHidden){
[self showPickerView];
}
else{
[self hidePickerView];
}
}