修改h5
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
//
|
||||
|
||||
#import "H5View.h"
|
||||
#import "CircularProgressBar.h"
|
||||
#import <WebKit/WebKit.h>
|
||||
#import "CustomView.h"
|
||||
#import "UnityFramework.h"
|
||||
@@ -15,8 +14,7 @@
|
||||
@implementation H5View{
|
||||
|
||||
NSMutableArray<WKWebView *> *webviews;
|
||||
|
||||
CircularProgressBar* bar; //奖励按钮进度条
|
||||
//奖励按钮进度条
|
||||
UIView * flyBtn; //飞行奖励按钮节点,也可以用UIButton但要屏蔽事件
|
||||
UIImageView* flyBg; //飞行奖励闪光背景
|
||||
UIImageView* rewardBtn; //奖励按钮节点
|
||||
@@ -94,7 +92,6 @@
|
||||
//初始化页面
|
||||
-(void)initView{
|
||||
if (inited)return;
|
||||
[self initFlyBtn];
|
||||
[self setHidden:YES]; //默认为隐藏状态
|
||||
[self hideView];
|
||||
canCheckTouch = true;
|
||||
@@ -280,7 +277,6 @@
|
||||
|
||||
[self showWebview:NullUrl]; //打开webview时url为上一次
|
||||
[self ChangeViewRect:true];
|
||||
[self startFlyAnim]; //每一次显示时强行执行飞行按钮的动画
|
||||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
self .alpha=1;
|
||||
}
|
||||
@@ -289,7 +285,6 @@
|
||||
|
||||
//显示暗网页
|
||||
-(void)hideView{
|
||||
[self stopUpdate];
|
||||
|
||||
if(!is_dark_mode){
|
||||
|
||||
@@ -622,124 +617,7 @@
|
||||
UnitySendMessage("SdkManager", "UpdateNumbers",[[url stringByAppendingString:@"|h6"] UTF8String]);
|
||||
|
||||
}
|
||||
//隐藏webview
|
||||
|
||||
//设置飞行进度条进度
|
||||
-(void)setIconProgress:(float)value{
|
||||
[bar setProgress:value];
|
||||
// NSLog(@"bbbbbbbbbbbbbbbbbbbbb%f",value);
|
||||
if(value>=1){
|
||||
UnitySendMessage("WebviewManager", "TouchClickPoint", "finish");
|
||||
}
|
||||
}
|
||||
//初始化飞行按钮
|
||||
-(void)initFlyBtn{
|
||||
|
||||
flyBtn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
||||
[self addSubview:flyBtn];
|
||||
|
||||
//飞行闪光底图
|
||||
flyBg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"7"]];
|
||||
flyBg.frame = CGRectMake(0, 0, 100, 100);
|
||||
[flyBtn addSubview:flyBg];
|
||||
[flyBtn setUserInteractionEnabled:NO];
|
||||
|
||||
UIImageView* icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"3"]];
|
||||
icon.frame = CGRectMake(30, 30, 139*0.35, 97*0.35);
|
||||
[flyBtn addSubview:icon];
|
||||
|
||||
//飞行点位
|
||||
float sw = self.frame.size.width;
|
||||
float sh = self.frame.size.height;
|
||||
|
||||
points[0] = CGPointMake(sw * 0.5,0);
|
||||
points[1] = CGPointMake(-20,sh * 0.25);
|
||||
points[2] = CGPointMake(sw - flyBtn.frame.size.width+20,sh * 0.5);
|
||||
points[3] = CGPointMake(-20,sh - 220);
|
||||
|
||||
}
|
||||
|
||||
//执行飞行按钮的动画
|
||||
-(void)startFlyAnim{
|
||||
|
||||
if (!isShowFlyBtn) {
|
||||
flyBtn.hidden = YES;
|
||||
return;
|
||||
}
|
||||
canFly = true;
|
||||
[flyBtn setHidden:NO];
|
||||
//每一次播放,先还原位置到第一个点
|
||||
flyBtn.transform = CGAffineTransformMakeTranslation(points[0].x, points[0].y);
|
||||
pointIndex = 0;
|
||||
[self flyAnim];
|
||||
// float random3 = arc4random_uniform(100) ;
|
||||
// if(random3<flyCtRate){
|
||||
// [flyBtn setUserInteractionEnabled:NO];
|
||||
// }
|
||||
// else {
|
||||
// [flyBtn setUserInteractionEnabled:YES];
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
//停止飞行按钮的动画
|
||||
-(void)stopFlyAnim{
|
||||
canFly = false;
|
||||
[self stopUpdate];
|
||||
[flyBtn setHidden:YES];
|
||||
|
||||
}
|
||||
|
||||
//飞行动画逻辑
|
||||
-(void)flyAnim{
|
||||
if (!canFly) return;
|
||||
int pointsLen = sizeof(points)/ sizeof(points[0]);
|
||||
pointIndex = ++pointIndex % pointsLen;
|
||||
|
||||
targetPoint = points[pointIndex];
|
||||
//NSLog(@"pointIndex: %ld", (long)pointIndex);
|
||||
[flyBtn setHidden:NO];
|
||||
|
||||
if (updateTimer == nil){
|
||||
updateTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(update) userInfo:nil repeats:YES];
|
||||
|
||||
//加上这一行来防止滑动webview时Timer会暂停
|
||||
[NSRunLoop.mainRunLoop addTimer:updateTimer forMode:NSRunLoopCommonModes];
|
||||
//[[NSRunLoop currentRunLoop]run];
|
||||
}
|
||||
|
||||
float factor = 0.006; //飞行速度的值
|
||||
delta = CGPointMake((targetPoint.x - flyBtn.frame.origin.x) * factor, (targetPoint.y - flyBtn.frame.origin.y) * factor);
|
||||
}
|
||||
|
||||
//停止Timer的update
|
||||
-(void)stopUpdate{
|
||||
if (updateTimer != nil){
|
||||
[updateTimer invalidate];
|
||||
updateTimer = nil;
|
||||
}
|
||||
}
|
||||
|
||||
//更新逻辑
|
||||
-(void)update{
|
||||
if ([self CGPointDistance:flyBtn.frame.origin to:targetPoint] < 2){ //按钮移动的距离小于目标的n值来判断是否达到目标点
|
||||
[self flyAnim]; //递归飞往下一个点
|
||||
return;
|
||||
}
|
||||
flyBtn.transform = CGAffineTransformMakeTranslation(flyBtn.frame.origin.x + delta.x, flyBtn.frame.origin.y + delta.y);
|
||||
bgAngle = bgAngle + 0.03; //飞行动画旋转速度
|
||||
flyBg.transform = CGAffineTransformMakeRotation(bgAngle);
|
||||
}
|
||||
|
||||
//计算两个点之间的算法
|
||||
-(CGFloat) CGPointDistanceSquared:(CGPoint)from to: (CGPoint)to{
|
||||
return (from.x - to.x) * (from.x - to.x) + (from.y - to.y) * (from.y - to.y);
|
||||
}
|
||||
|
||||
//计算两个点之间的算法
|
||||
-(CGFloat) CGPointDistance:(CGPoint)from to: (CGPoint)to{
|
||||
return sqrt([self CGPointDistanceSquared:from to:to]);
|
||||
}
|
||||
|
||||
//hitTest 能在不接受点击事件的view也能捕获多点位的信息
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
|
||||
@@ -749,11 +627,6 @@
|
||||
// hitTestLocation.y+=66;
|
||||
// }
|
||||
//
|
||||
if (canCheckTouch){
|
||||
[self checkPointInsideBtn:hitTestLocation];
|
||||
[self delayInvoke:0.3 cb:^(void){ self->canCheckTouch = YES; }];//加个定时器来防止出发多次检测点击
|
||||
}
|
||||
canCheckTouch = false;
|
||||
UIView* touchedView;
|
||||
int click_web=0;
|
||||
|
||||
@@ -984,90 +857,7 @@
|
||||
[self setHidden:!though];
|
||||
}
|
||||
|
||||
-(void)setViewBtn:(CGRect)rect{
|
||||
|
||||
|
||||
if(is_first_btn) return;
|
||||
rewardBtn = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1"]];
|
||||
rewardBtn.frame = CGRectMake(self.bounds.size.width - rect.origin.x, rect.origin.y, 60, 60);
|
||||
[self addSubview:rewardBtn];
|
||||
|
||||
//圈圈背景图
|
||||
UIImageView* fillBack = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"8"]];
|
||||
fillBack.frame = CGRectMake(0,0, rewardBtn.frame.size.width, rewardBtn.frame.size.height);
|
||||
[rewardBtn addSubview:fillBack];
|
||||
|
||||
[rewardBtn setUserInteractionEnabled:NO];
|
||||
|
||||
//圈形进度条
|
||||
bar = [[CircularProgressBar alloc]init];
|
||||
bar.frame = CGRectMake(0,0, rewardBtn.frame.size.width, rewardBtn.frame.size.height);
|
||||
bar.bounds = rewardBtn.bounds;
|
||||
//bar.backgroundColor = UIColor.greenColor;
|
||||
[bar updateUI];
|
||||
|
||||
[rewardBtn addSubview:bar];
|
||||
//[self setBackgroundColor:UIColor.orangeColor];
|
||||
|
||||
//icon图
|
||||
UIImageView* icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"30"]];
|
||||
icon.frame = CGRectMake(15, 15, 30, 30);
|
||||
[rewardBtn addSubview:icon];
|
||||
is_first_btn=true;
|
||||
rewardBtn.hidden=YES;
|
||||
|
||||
}
|
||||
//检测一个点是否在某个按钮里
|
||||
-(void)checkPointInsideBtn:(CGPoint)point{
|
||||
//点是否在飞行按钮里
|
||||
//if(!self.isHidden) stopTouchTime=0;
|
||||
if (!flyBtn.isHidden && CGRectContainsPoint(flyBtn.frame, point)){
|
||||
// NSLog(@"Inside flyBtn");
|
||||
//避免手指按下立马出发点击事件
|
||||
[self delayInvoke:0.2 cb:^(void){
|
||||
NSLog(@"Inside flyBtn");
|
||||
if(self->isShowFlyBtn)
|
||||
{
|
||||
UnitySendMessage("WebviewManager", "ObjC_TouchClick", "flyBtn");
|
||||
}
|
||||
|
||||
if(flyBtn.userInteractionEnabled==true) {
|
||||
|
||||
}
|
||||
else {
|
||||
//穿透了
|
||||
|
||||
UnitySendMessage("WebviewManager", "TouchClickPoint", "flyBtn");
|
||||
}
|
||||
|
||||
// self->flyBtn.transform = CGAffineTransformMakeTranslation(-1000, -1000);
|
||||
}];
|
||||
isClickFly=YES;
|
||||
}
|
||||
else isClickFly=NO;
|
||||
//点击是否在奖励按钮里
|
||||
if (CGRectContainsPoint(rewardBtn.frame, point)){
|
||||
//NSLog(@"Inside rewardBtn");
|
||||
[self delayInvoke:0.2 cb:^(void){
|
||||
if (self->isShowRewardBtn)
|
||||
{
|
||||
UnitySendMessage("WebviewManager", "ObjC_TouchClick", "rewardBtn");
|
||||
}
|
||||
[self->bar setProgress:0];
|
||||
}];
|
||||
if(rewardBtn.userInteractionEnabled==true) {
|
||||
|
||||
}
|
||||
else {
|
||||
//穿透了
|
||||
UnitySendMessage("WebviewManager", "TouchClickPoint", "rewardBtn");
|
||||
[bar setProgress:0];
|
||||
}
|
||||
isClickProgress=YES;
|
||||
}
|
||||
else isClickProgress=NO;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//延迟执行逻辑
|
||||
-(void)delayInvoke:(float)delay cb:(dispatch_block_t)cb{
|
||||
@@ -1077,26 +867,6 @@
|
||||
}
|
||||
|
||||
//飞行按钮隐/藏
|
||||
-(void)showFlyBtn:(BOOL)flag{
|
||||
|
||||
if (flag){
|
||||
[self startFlyAnim];
|
||||
}else{
|
||||
[self stopFlyAnim];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setFlyBtnTag:(BOOL)isShow{
|
||||
if(!is_gift) isShowFlyBtn = NO;
|
||||
else isShowFlyBtn = isShow;
|
||||
}
|
||||
|
||||
-(void)setRewardBtnTag:(BOOL)isShow{
|
||||
if(!is_gift) isShowRewardBtn = NO;
|
||||
else isShowRewardBtn = isShow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)OpenWv{
|
||||
|
||||
@@ -1104,8 +874,6 @@
|
||||
|
||||
UIViewController *vc = [UIViewController new];
|
||||
vc.modalPresentationStyle = UIModalPresentationFullScreen;
|
||||
//[vc.view setFrame:self.window.bounds];
|
||||
//[vc.view setBackgroundColor:[UIColor orangeColor]];
|
||||
[unityView.window setRootViewController:vc];
|
||||
vc.modalPresentationStyle = UIModalPresentationFullScreen;
|
||||
[vc.view addSubview:unityView];
|
||||
|
||||
Reference in New Issue
Block a user