ifish/Ifish/views/IfishHomeAdVIew/IfishStartAdView.m

114 lines
3.6 KiB
Objective-C

//
// IfishStartAdView.m
// Test1
//
// Created by lianxiang on 16/11/27.
// Copyright © 2016年 lianxiangpro. All rights reserved.
//
#import "IfishStartAdView.h"
#define KWid_Scale [UIScreen mainScreen].bounds.size.width/375.0f
#define KHeigt_Scale [UIScreen mainScreen].bounds.size.height/667.0f
@interface IfishStartAdView()
@property(nonatomic,strong) UIView*holdView;
@end
@implementation IfishStartAdView
-(id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
//self.backgroundColor = [UIColor clearColor];
[self initSubsWith:(CGRect)frame];
}
return self;
}
-(void)initSubsWith:(CGRect)frame
{
//UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]
// initWithTarget:self action:@selector(backViewTap:)];
//[self addGestureRecognizer:tap];
//self.holdView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 100, 200)];
//self.holdView.backgroundColor = [UIColor whiteColor];
//self.holdView.center = self.center;
//self.holdView.layer.masksToBounds = YES;
//self.holdView.layer.cornerRadius = 5;
//[self addSubview:self.holdView];
UIView *aplpaback = [[UIView alloc] initWithFrame:frame];
aplpaback.backgroundColor = [UIColor blackColor];
aplpaback.alpha = 0.6;
[self addSubview:aplpaback];
CGFloat imagW= self.frame.size.width - KWid_Scale*36*2;
CGFloat imagH = imagW*1.2;
UIImageView *holdbackImgView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0,imagW ,imagH)];
holdbackImgView.image = [UIImage imageNamed:@"home_care_popup"];
holdbackImgView.center = self.center;
holdbackImgView.userInteractionEnabled = YES;
holdbackImgView.alpha = 1;
[self addSubview:holdbackImgView];
//删除按钮大小
CGFloat btnW= KWid_Scale *30;
//X 方向与 图片间距
CGFloat delecBtnSpaceX = KWid_Scale *10;
//Y 方向与 图片间距
CGFloat delecBtnSpaceY = delecBtnSpaceX + KHeigt_Scale *32;
UIButton *delectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
delectBtn.frame = CGRectMake(CGRectGetWidth(holdbackImgView.frame) - delecBtnSpaceX -btnW,delecBtnSpaceY, btnW, btnW);
[delectBtn setBackgroundImage:[UIImage imageNamed:@"home_popup_cancel"] forState:UIControlStateNormal];
[delectBtn addTarget:self action:@selector(removeAd) forControlEvents:UIControlEventTouchUpInside];
[holdbackImgView addSubview:delectBtn];
//体验按钮
CGFloat tybtnW= KWid_Scale *228;
CGFloat tybtnH= tybtnW *0.19;
CGFloat tybtnY= CGRectGetHeight(holdbackImgView.frame) - KHeigt_Scale *26 - tybtnH;
UIButton *tyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
tyBtn.frame = CGRectMake(CGRectGetWidth(holdbackImgView.frame)/2 - tybtnW/2,tybtnY,tybtnW, tybtnH);
//[tyBtn setBackgroundImage:[UIImage imageNamed:@"home_button"] forState:UIControlStateNormal];
[tyBtn setImage:[UIImage imageNamed:@"home_popup_button"] forState:UIControlStateNormal];
[tyBtn addTarget:self action:@selector(tybtnAction) forControlEvents:UIControlEventTouchUpInside];
[holdbackImgView addSubview:tyBtn];
[self bringSubviewToFront:holdbackImgView];
}
-(void)tybtnAction{
[self removeFromSuperview];
[self.delegate goButtonAction];
}
-(void)removeAd{
[self removeFromSuperview];
}
-(void)backViewTap:(UITapGestureRecognizer *)tap{
CGPoint point = [tap locationInView:self];
CGRect holdViewRect = self.holdView.frame;
bool locationin=CGRectContainsPoint(holdViewRect, point);
if (locationin) {
return;
}
[self removeFromSuperview];
}
@end