如何像 UIActionSheet 一样从屏幕底部呈现 UIView? [英] How can I present a UIView from the bottom of the screen like a UIActionSheet?

查看:19
本文介绍了如何像 UIActionSheet 一样从屏幕底部呈现 UIView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 UIView 像 UIActionSheet 一样从屏幕底部向上滑动(并保持在屏幕中间).我怎样才能做到这一点?

I'd like a UIView to slide up from the bottom of the screen (and stay mid-screen) like a UIActionSheet. How can I accomplish this?

更新:我正在使用以下代码:

TestView* test = [[TestView alloc] initWithNibName:@"TestView" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

test.view.center = CGPointMake(160,100);
//test.view.frame = CGRectMake(0, 0, 160, 210);
[[[UIApplication sharedApplication] keyWindow] addSubview:test.view];

[UIView commitAnimations];  

视图似乎从角落开始动画并出现在角落中.我怎样才能让它从底部向上滑动?靠近!

The view seems to be animating from the corner and appearing in the corner. How can I make it slide up from the bottom? Getting close!

推荐答案

做马特在这里所做的,只是改变价值观和方向.如果您以后需要,我在家里有代码可以从底部执行此操作(我会更新这篇文章).

Do what Matt did here, but just change the values and direction. I have code at home to do this from the bottom if you need it later (I'll update this post).

链接:http://cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html

另外,不要忘记取出将主视图向下移动的代码(这样 UIView 就像一个 ActionSheet 一样弹出顶部)

Also, don't forget to take out the bit of code that shifts the main view downward (so instead the UIView just pops over top like an ActionSheet)

更新代码:

这是我在我的一个应用程序中用来显示/隐藏一些选项"视图的方法:

This is what I use in one of my apps to show/hide a little "options" view:

- (void)toggleOptions:(BOOL)ViewHidden
{
// this method opens/closes the player options view (which sets repeat interval, repeat & delay on/off)

if (ViewHidden == NO)
{
    // delay and move view out of superview
    CGRect optionsFrame = optionsController.view.frame;

    [UIView beginAnimations:nil context:nil];

    optionsFrame.origin.y += optionsFrame.size.height;
    optionsController.view.frame = optionsFrame;

    [UIView commitAnimations];

    [optionsController.view
     performSelector:@selector(removeFromSuperview)
     withObject:nil
     afterDelay:0.5];
    [optionsController
     performSelector:@selector(release)
     withObject:nil
     afterDelay:0.5];
    optionsController = nil;
}
else
{
    optionsController = [[PlayOptionsViewController alloc] init];

    //
    // Position the options at bottom of screen
    //
    CGRect optionsFrame = optionsController.view.frame;
    optionsFrame.origin.x = 0;
    optionsFrame.size.width = 320;
    optionsFrame.origin.y = 423;

    //
    // For the animation, move the view up by its own height.
    //
    optionsFrame.origin.y += optionsFrame.size.height;

    optionsController.view.frame = optionsFrame;
    [window addSubview:optionsController.view];

    [UIView beginAnimations:nil context:nil];

    optionsFrame.origin.y -= optionsFrame.size.height;
    optionsController.view.frame = optionsFrame;

    [UIView commitAnimations];
}
}

这篇关于如何像 UIActionSheet 一样从屏幕底部呈现 UIView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆