我如何设置像警报一样的视图并在 iOS 中自动隐藏
how can i set view like alert and hide automatically in iOS
在我的应用程序中,我想设置像警报一样的黑色视图,它会随着淡入淡出动画自动隐藏。
喜欢这个观点。此 requirement.I 可用的任何控件都是 iOS 中的新控件 development.Thank 您在高级中。
你好 这些是静态方法放在你的静态 class.
+(void)ShowSimpleBlackAlert:(NSString *)str
{
CGSize sizeLine = [StaticClass getFrameFromString:str :[UIScreen mainScreen].bounds.size.width-60 :[UIFont fontWithName:font_NAME_OpenSans size:15]]; // user your custom font
UIView * viewAlert =[[UIView alloc] initWithFrame:CGRectMake(20,([UIScreen mainScreen].bounds.size.height-50)/2,[UIScreen mainScreen].bounds.size.width-40,sizeLine.height+50)];
viewAlert.backgroundColor=[UIColor darkGrayColor];
viewAlert.alpha=0.0;
viewAlert.layer.cornerRadius=5.0;
viewAlert.tag=200;
UILabel *_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0,(viewAlert.frame.size.height-sizeLine.height)/2,viewAlert.frame.size.width-20,sizeLine.height)];
_titleLabel.textColor=[UIColor whiteColor];
_titleLabel.numberOfLines=0;
_titleLabel.font =[UIFont fontWithName:font_NAME_OpenSans size:15.0]; // user your custom font
_titleLabel.textAlignment=NSTextAlignmentCenter;
_titleLabel.text=str;
[viewAlert addSubview:_titleLabel];
[[UIApplication sharedApplication].keyWindow addSubview:viewAlert];
[UIView animateWithDuration:1.0
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
viewAlert.alpha = 1.0;
}
completion:nil];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(hideSimpleBlackAlert) userInfo:nil repeats:NO];
}
和其他隐藏方法...
+(void)hideSimpleBlackAlert
{
[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
[[[UIApplication sharedApplication].keyWindow viewWithTag:200] removeFromSuperview];
}
completion:nil];
}
和这样的用户
[yourStaticClass ShowAlert:@"put here your message "];
根据您的要求使用第三方库。
1) AFMInfoBanner。它可用于不引人注意地通知用户不需要任何特定操作或 UI 锁定的成功或错误事件。
2) ALAlertBanner。它是 iOS(iPhone 和 iPad)的插件组件,允许您以可自定义和可配置的方式显示漂亮的警报横幅。
Andriod 喜欢 ios 中的吐司。您可以根据需要进行修改
在我的应用程序中,我想设置像警报一样的黑色视图,它会随着淡入淡出动画自动隐藏。
喜欢这个观点。此 requirement.I 可用的任何控件都是 iOS 中的新控件 development.Thank 您在高级中。
你好 这些是静态方法放在你的静态 class.
+(void)ShowSimpleBlackAlert:(NSString *)str
{
CGSize sizeLine = [StaticClass getFrameFromString:str :[UIScreen mainScreen].bounds.size.width-60 :[UIFont fontWithName:font_NAME_OpenSans size:15]]; // user your custom font
UIView * viewAlert =[[UIView alloc] initWithFrame:CGRectMake(20,([UIScreen mainScreen].bounds.size.height-50)/2,[UIScreen mainScreen].bounds.size.width-40,sizeLine.height+50)];
viewAlert.backgroundColor=[UIColor darkGrayColor];
viewAlert.alpha=0.0;
viewAlert.layer.cornerRadius=5.0;
viewAlert.tag=200;
UILabel *_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0,(viewAlert.frame.size.height-sizeLine.height)/2,viewAlert.frame.size.width-20,sizeLine.height)];
_titleLabel.textColor=[UIColor whiteColor];
_titleLabel.numberOfLines=0;
_titleLabel.font =[UIFont fontWithName:font_NAME_OpenSans size:15.0]; // user your custom font
_titleLabel.textAlignment=NSTextAlignmentCenter;
_titleLabel.text=str;
[viewAlert addSubview:_titleLabel];
[[UIApplication sharedApplication].keyWindow addSubview:viewAlert];
[UIView animateWithDuration:1.0
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
viewAlert.alpha = 1.0;
}
completion:nil];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(hideSimpleBlackAlert) userInfo:nil repeats:NO];
}
和其他隐藏方法...
+(void)hideSimpleBlackAlert
{
[UIView animateWithDuration:2.0
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
[[[UIApplication sharedApplication].keyWindow viewWithTag:200] removeFromSuperview];
}
completion:nil];
}
和这样的用户
[yourStaticClass ShowAlert:@"put here your message "];
根据您的要求使用第三方库。
1) AFMInfoBanner。它可用于不引人注意地通知用户不需要任何特定操作或 UI 锁定的成功或错误事件。
2) ALAlertBanner。它是 iOS(iPhone 和 iPad)的插件组件,允许您以可自定义和可配置的方式显示漂亮的警报横幅。
Andriod 喜欢 ios 中的吐司。您可以根据需要进行修改