This commit is contained in:
edy
2026-07-13 10:56:08 +08:00
parent 253ce0bc2b
commit 9f39e0cc62
3 changed files with 3 additions and 357 deletions
-122
View File
@@ -28,135 +28,13 @@
}
-(void)initView{
// Initialize a WKWebViewConfiguration object.
// UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
// [unityView addGestureRecognizer:gest];
// [gest setDelegate:self];
// CustomGestureDelegate *deleg = [[CustomGestureDelegate alloc] init];
// [gest setDelegate:deleg];
// gest.cancelsTouchesInView = false; // to recieve touchesBegan callback even if gesture is recognized
// gest.delaysTouchesBegan = false; // to not delay touchesBegan callback
// gest.delaysTouchesEnded = false; // to not delay touchesEnded callback
// CustomGestureDelegate *deleg = [[CustomGestureDelegate alloc] init];
// [gest setDelegate:deleg];
// NSTimeInterval delayInSeconds = 7;
// dispatch_time_t popTime2 = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
// dispatch_after(popTime2, dispatch_get_main_queue(), ^(void){
//
// [self loop];
// });
// [self setWebviewPadding:CGRectMake(0, 120, 0, 180)];
}
//-(void)setConfig:(ViewCfg)cfg{
// config = cfg;
//
// webview.frame = config.rect;
// // webview.frame = CGRectMake(0, 100, self.bounds.size.width, 500);
// //canCT = YES;
//}
// -(void)handleTap:(UITapGestureRecognizer*) gest{
// CGPoint pt = [gest locationInView:webview];
// // NSLog(@"GestureRecognizer x:%f, y:%f", pt.x, pt.y);
// // if (gest.state == UIGestureRecognizerStateBegan){
// // NSLog(@"Begin x:%f, y:%f", pt.x, pt.y);
// // }
// if (gest.state == UIGestureRecognizerStateEnded){
// NSLog(@"GestureRecognizer End x:%f, y:%f", pt.x, pt.y);
// }
// }
// //- (void) touchesBegan:(NSSet *)touches withEvent:(nullable UIEvent *)event{
// // UITouch *touch = [[event allTouches] anyObject];
// //
// // CGPoint location = [touch locationInView:self];
// // beginTouches = touches;
// // beginEvent = event;
// // NSLog(@"Touch Began CustomView");
// //}
// //
// //- (void) touchesEnded:(NSSet *)touches withEvent:(nullable UIEvent *)event{
// // UITouch *touch = [[event allTouches] anyObject];
// //
// // CGPoint location = [touch locationInView:self];
// // beginTouches = touches;
// // beginEvent = event;
// // NSLog(@"Touch Ended CustomView");
// //}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
//UIView* touchedView = [super hitTest:point withEvent:event];
// if([[H5View shared] isDarkThough]){
// NSLog(@"Point coordinates: x = %f, y = %f", point.x, point.y);
// NSLog(@"Point coordinates: max = %f,",self.bounds.size.width);
UIView* testview = [ [H5View shared]hitTest:point withEvent:event];
return testview;
// }
// else
// return touchedView;
}
// -(void)showWebview:(NSString*)url{
// // NSLog(@"Native showWebview: %@", url);
// NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
// [webview loadRequest:request];
// if (webview.superview == nil)
// [self insertSubview:webview atIndex:0];
// isWebviewOpen = YES;
// }
// -(void)hideWebview{
// // NSLog(@"Native hideWebview");
// [webview removeFromSuperview];
// isWebviewOpen = NO;
// }
// -(void)scrollWebview:(CGPoint)offset{
// CGPoint pt = [webview.scrollView contentOffset];
// if (offset.y < 0 && pt.y <= 0) return;
// float val = pt.y + offset.y*0.5;
// if (val<0) val = 0;
// [webview.scrollView setContentOffset:CGPointMake(0, val)];
// }
// -(void)setTouchWebview:(BOOL)flag forceCT:(BOOL)force{
// if (!isWebviewOpen) return;
// isTouchWebView = flag;
// //unityView.userInteractionEnabled = !flag;
// if (canCT || force){
// if (!CGRectContainsPoint(webview.bounds, hitTestLocation))
// return;
// [self doCT];
// }
// }
// -(void)tapWithPoint:(CGPoint)zspoint{
// [Helpers helpAt:1 AtPoint:zspoint withTouchPhase:UITouchPhaseBegan];
// [Helpers helpAt:1 AtPoint:zspoint withTouchPhase:UITouchPhaseEnded];
// }
// -(void)enableCT:(BOOL)flag{
// // NSLog(@"Native enableCT: %d",flag);
// canCT = flag;
// }
// -(void)doCT{
// NSTimeInterval delayInSeconds = 0.1;
// dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
// dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// // NSLog(@"CT x:%f, y:%f", self->hitTestLocation.x, self->hitTestLocation.y);
// self->unityView.userInteractionEnabled = false;
// [self tapWithPoint:self->hitTestLocation];
// self->unityView.userInteractionEnabled = true;
// });
// }
@end
+1 -233
View File
@@ -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,91 +857,8 @@
[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{
NSTimeInterval delayInSeconds = delay;
@@ -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];
+1 -1
View File
@@ -1,4 +1,4 @@
#import <UnityFramework/UnityFramework-Swift.h>
extern "C" {
#include "H5View.h"
NSString *stringFromChar(const char *input) {