2013-07-24 47 views
0

我很抱歉,如果这个问题是非常基本的。我一直在谷歌搜索,但似乎无法找到一个下拉警报横幅/标签(我不知道适当的期限)的API /参考,因此我张贴在这里。iOS警告横幅/标签?

这是:在其中包含“请输入有效的电子邮件地址”的标签/横幅。

所以这里我的问题:

  • ,这是什么(???警告标语通知标签)
  • 我试图完成类似的功能,以适当的期限显示什么在图像中,基本上,如果任何字段无效,“标签/横幅”将从导航栏的下面随其中的消息展开: 如果这只是一个UILabel,那么添加展开动画的最简单方法是什么? 如果它是内置的东西,因为我看过一堆应用程序用于提醒,请让我知道它的名字。
+0

您可能正在寻找此... https://www.cocoacontrols.com/controls/ajnotificationview – jsetting32

回答

4

看看here,我相信你能找到满足你需求的东西。

其基本思想是,它只是一个UIView,你从屏幕的顶部(在非常基本的)的顶部动画。您可以通过添加渐变得到了很多票友,触摸识别器来关闭它,等,但几乎得到基线功能,你只需做这样的事情:

//Create a view to hold the label and add images or whatever, place it off screen at -100 
UIView *alertview = [[UIView alloc] initWithFrame:CGRectMake(0, -100, CGRectGetWidth(self.view.bounds), 100)]; 

//Create a label to display the message and add it to the alertView 
UILabel *theMessage = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(alertview.bounds), CGRectGetHeight(alertview.bounds))]; 
theMessage.text = @"I'm an alert"; 
[alertview addSubview:theMessage]; 

//Add the alertView to your view 
[self.view addSubview:alertview]; 

//Create the ending frame or where you want it to end up on screen, in this case 0 y origin 
CGRect newFrm = alertview.frame; 
newFrm.origin.y = 0; 

//Animate it in 
[UIView animateWithDuration:2.0f animations:^{ 
    alertview.frame = newFrm; 
}]; 
+0

这只是一个侧面的问题,因为我从来没有以编程方式创建视图。如果我使用ARC,这个视图会在添加到父视图后立即跟踪到,还是需要在某处显式释放它? (我正在处理渐变和颜色,所以我还有那些应该发布的资源?) – Naveed

+0

如果您使用ARC,并且只要将它添加到父视图中,就不需要将其释放。 – random

0

在过去的动画警报更容易控制,可以嵌入到你的UIStackView自定义视图和简单的显示/隐藏它的动画块。这样可以显着减少动画显示警报可见性所需的代码量。