首页 > 代码库 > 简单弹出视图

简单弹出视图

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#import "loveView.h"
//点击按钮
-(void)buttonclick
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
loveView *loveview = [[loveView alloc] initWithFrame:window.bounds];
loveview.alpha = 0;
[window.rootViewController.view addSubview:loveview];
[UIView animateWithDuration:0.5
                 animations:^{
        loveview.alpha = 1.0;
    }
 ];
}

  

#import "loveView.h"

@implementation loveView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        [self   creatView];
        
    }
    return self;
}

-(void)creatView
{

    [self setBackgroundColor:[UIColor clearColor]];
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    backView.center = self.center;
    [backView setBackgroundColor:[UIColor blackColor]];
    [self addSubview:backView];
    backView.alpha = 0.3;
    
    UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 200)];
    mainView.center = self.center;
    [mainView setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:mainView];
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10,260, 50)];
    label.text = @"   Love Me?那就告诉全世界吧!";
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor  blueColor];
    
    UIButton *yesBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 60, 260, 50)];
    [yesBtn setBackgroundColor:[UIColor  greenColor]];
    [yesBtn setTitle:@"好!" forState:UIControlStateNormal];
    [yesBtn setTitleColor:[UIColor  redColor] forState:UIControlStateNormal];
    [yesBtn addTarget:self action:@selector(yesBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *noBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 130, 260, 50)];
    [noBtn setBackgroundColor:[UIColor redColor]];
    [noBtn setTitle:@"不,谢谢" forState:UIControlStateNormal];
    [noBtn addTarget:self action:@selector(noBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [mainView addSubview:label];
    [mainView addSubview:yesBtn];
    [mainView addSubview:noBtn];

}


- (void)yesBtnClick
{
    
    NSLog(@"YES!!!");
    [UIView animateWithDuration:0.5 animations:^{
        
        self.alpha = 0.0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}


- (void)noBtnClick
{
    NSLog(@"NO!!!");
    [UIView animateWithDuration:0.5 animations:^{
        
        self.alpha = 0.0;
        
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}



@end