状态栏弹出提示框代码

来源:互联网 发布:杭州美工招聘信息 编辑:程序博客网 时间:2024/05/18 21:48

-(void)postStatusBarNotice:(NSString *)info duration:(NSTimeInterval)time{

  statusWin=[[UIWindowalloc] initWithFrame:CGRectMake(0, 0, 320, 20)];

  [statusWinsetWindowLevel:UIWindowLevelAlert];

  msgLabel=[[UILabelalloc]initWithFrame:statusWin.frame];

 msgLabel.text=info;

  msgLabel.backgroundColor=[UIColorblackColor];

  msgLabel.textColor=[UIColorwhiteColor];

  msgLabel.textAlignment=UITextAlignmentCenter;

  msgLabel.font=[UIFontsystemFontOfSize:12];

 msgLabel.alpha=0.7;

  [statusWin addSubview:msgLabel];

  [statusWinmakeKeyAndVisible];

  

 AppDelegate *appDelegate=(AppDelegate *)[UIApplicationsharedApplication].delegate;

  [appDelegate.windowmakeKeyAndVisible];

  

  [UIViewbeginAnimations:nilcontext:nil];

  [UIViewsetAnimationDuration:time];

  [UIViewsetAnimationCurve:UIViewAnimationCurveEaseOut];

  [UIViewsetAnimationDelegate:self];

  [UIViewsetAnimationDidStopSelector:@selector(hideCustomStatusBar)];

  msgLabel.alpha=1;

  [UIViewcommitAnimations];

}


-(void)hideCustomStatusBar{

  [UIViewanimateWithDuration:.3 animations:^{

    msgLabel.transform=CGAffineTransformMakeTranslation(320, 0);

  }completion:^(BOOL finished){

    [msgLabelrelease];

    CFShow(statusWin);

    [statusWin release];

    statusWin = nil;

  }];



0 0
原创粉丝点击