我想创建一个自定义alertView,其效果类似于instagram应用(当用户输入错误的密码或电子邮件时,登录/注册视图)。警报动画应下拉并暂停以供用户阅读约2秒钟,然后alertView再次上升。我怎么能这样做?
以下是我现在所拥有的:
- (UIView *) createAlertViewWithViewController:(UIViewController *)viewController andText:(NSString *)alertText
{
alertView = [[UIView alloc] init];
[alertView setBackgroundColor:ALERT_VIEW_COLOR];
[alertView setFrame:ALERT_VIEW_HIDE_FRAME];
UILabel *alertViewLabel = [[UILabel alloc] init];
[alertViewLabel setFrame:CGRectMake(viewController.view.bounds.origin.x, 7, viewController.view.bounds.size.width, ALERT_VIEW_HEIGHT)];
[alertViewLabel setTextAlignment:NSTextAlignmentCenter];
[alertViewLabel setTextColor:[UIColor whiteColor]];
[alertViewLabel setFont:[UIFont systemFontOfSize:13.0f]];
[alertViewLabel setText:alertText];
[alertView addSubview:alertViewLabel];
CGPoint originalCenter = alertView.center;
[UIView animateWithDuration:0.5
animations:^{
CGPoint center = alertView.center;
center.y += ALERT_VIEW_HEIGHT;
alertView.center = center;
}
completion:^(BOOL finished){
[UIView animateWithDuration:3.0
animations:^{
alertView.center = originalCenter;
}
completion:^(BOOL finished){
;
}];
}];
return alertView;
}
我的代码现在下降并立即上升,但我想要的是,当它完成下拉动画时,它会暂停约2秒,然后进行上升动画。
我现在已经搜索了3天,但我还没找到任何一个。
示例图像何时暂停2秒:
答案 0 :(得分:0)
你想要这个图书馆吗? https://github.com/problame/CSNotificationView
实施例
[CSNotificationView showInViewController:self
tintColor:[UIColor colorWithRed:0.000 green:0.6 blue:1.000 alpha:1]
image:nil
message:@"What's the meetup called?"
duration:2.f];
答案 1 :(得分:0)
我猜你正在寻找[UIView animateWithDuration:...
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
延迟等待你的动画。
答案 2 :(得分:0)
试试这个:
UILabel *myLable=[[UILabel alloc]init];
myLable.frame=CGRectMake(0, -50, 320, 50);
myLable.backgroundColor=[UIColor grayColor];
myLable.textAlignment=NSTextAlignmentCenter;
myLable.text=@"Your Error Message";
[self.view addSubview:myLable];
[self ShowAnimation:myLable currentFrame:CGRectMake(0, -50, 320, 50) newFrame:CGRectMake(0, 0, 320, 50)];
-(void)ShowAnimation:(UILabel *)aLable currentFrame:(CGRect)aCurrentFrame newFrame:(CGRect)aNewFrame
{
[aLable setFrame:aCurrentFrame];
[UIView animateWithDuration:1.5 animations:^{
[aLable setFrame:aNewFrame];
}completion:^(BOOL finished)
{
[aLable setFrame:aNewFrame];
[UIView animateWithDuration:1.5 delay:2.0 options:UIViewAnimationOptionCurveEaseIn
animations:^{
[aLable setFrame:aCurrentFrame];
}
completion:^(BOOL finished) {
}];
}];
}