我是iOS开发的新手,请注意我的问题。
正如我的标题所说,
我该如何像UIActionSheet
那样隐藏和显示带有动画的UIView
?
我在Google上搜索过,但是没有找到有效的解决方案。
我是iOS开发的新手,请注意我的问题。
正如我的标题所说,
我该如何像UIActionSheet
那样隐藏和显示带有动画的UIView
?
我在Google上搜索过,但是没有找到有效的解决方案。
请执行以下代码:
- (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);
}];
}
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];
}
-(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];
}
}