本篇文章主要介绍了详解iOS的冲顶大会辅助,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
本文介绍了iOS的冲顶大会辅助,分享给大家,具体如下:
CHDeclareClass(_TtC10LiveTrivia18LiveViewController)
CHOptimizedMethod(0, self,void,_TtC10LiveTrivia18LiveViewController,viewDidLoad){
CHSuper(0, _TtC10LiveTrivia18LiveViewController,viewDidLoad);
UIWindow *win = [UIApplication sharedApplication].keyWindow;
UIView *view = CHIvar(self, _view, __strong UIView *);
CGFloat offsetY = 80;
UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(view.frame)/2 + offsetY, CGRectGetWidth(view.frame), CGRectGetHeight(view.frame)/2 - offsetY)];
web.layer.cornerRadius = 4;
web.layer.masksToBounds = YES;
[win addSubview:web];
objc_setAssociatedObject(self, @"searchWeb", web, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
UIButton *moveWeb = [UIButton buttonWithType:UIButtonTypeSystem];
[moveWeb setTitle:@"Move" forState:UIControlStateNormal];
[moveWeb addTarget:self action:@selector(moveWebAction:) forControlEvents:UIControlEventTouchUpInside];
[moveWeb setFrame:CGRectMake(0, 0, CGRectGetWidth(web.frame), 45)];
moveWeb.backgroundColor = [UIColor whiteColor];
[web addSubview:moveWeb];
NSLog(@"%@",view.subviews[1].subviews[1]);
UIView *questionView = view.subviews[1].subviews[1];
[questionView addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew context:nil];
UILabel *qaLabel = questionView.subviews[3].subviews.firstObject;
UIButton *option1 = questionView.subviews[5].subviews[0];
UIButton *option2 = questionView.subviews[5].subviews[1];
UIButton *option3 = questionView.subviews[5].subviews[2];
objc_setAssociatedObject(self, @"qaLabel", qaLabel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, @"opation1", option1, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, @"opation2", option2, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, @"opation3", option3, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
NSLog(@"%@--%@---%@---%@",qaLabel,option1,option2,option3);
}
先添加到webView到window上,然后关联对象到LiveViewController上,留着后面用,加上button是用来控制webView的frame,下面的qaLabel是存放问题的,三个optionButton分别是三个选项。同样我们关联到controller上,我们还要监听questionView的alpha值的变化。
alpha值改变我们获取问题和选项去搜索
CHOptimizedMethod(4, self,void,_TtC10LiveTrivia18LiveViewController,observeValueForKeyPath,NSString *,keyPath,ofObject,id,object,change,NSDictionary*,change,context,void *,context){
NSLog(@"%@,%@",change,keyPath);
if ([change[@"new"] intValue] != 1) return;
NSString *questionStr = nil;
UILabel *qaLabel = objc_getAssociatedObject(self, @"qaLabel");
UIButton *option1 = objc_getAssociatedObject(self, @"opation1");
UIButton *option2 = objc_getAssociatedObject(self, @"opation2");
UIButton *option3 = objc_getAssociatedObject(self, @"opation3");
questionStr = [NSString stringWithFormat:@"%@ %@ %@ %@",qaLabel.text,option1.titleLabel.text,option2.titleLabel.text,option3.titleLabel.text];
NSString *wd = [questionStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.baidu.com/s?wd=%@",wd]];
UIWebView *web = objc_getAssociatedObject(self, @"searchWeb");
[web loadRequest:[NSURLRequest requestWithURL:url]];
NSLog(@"%@",questionStr);
}
最后点击button的事件我们得添加新的方法
%hook _TtC10LiveTrivia18LiveViewController
%new
- (void)moveWebAction:(UIButton *)btn{
NSLog(@"%@",btn.superview);
UIWebView *web = btn.superview;
CGFloat top = 150;
CGFloat offsetY = 80;
CGFloat originY = CGRectGetMinY(web.frame) == top?(kHeight/2 + offsetY):top;
CGFloat webHeight = CGRectGetMinY(web.frame) == top?(kHeight - top):(kHeight/2 - offsetY);
[UIView animateWithDuration:.3 animations:^{
CGRect newFrame = CGRectMake(0, offsetY, kWidth, webHeight);
web.frame = newFrame;
} completion:^(BOOL finished) {
}];
}
采用tweak的方式写的。忘了说试图class-dump出头文件的就放弃吧,代码是OC和Swift混编,所以.........
代码地址因为项目过大只上传了重要的代码文件。
最后还是声明一下,写这个纯属娱乐,请勿用作商业用途,否则后果自负。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:详解iOS的冲顶大会辅助
猜你喜欢
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
- Android实现监听音量的变化 2023-03-30
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
- Android studio实现动态背景页面 2023-05-23
- iOS 对当前webView进行截屏的方法 2023-03-01
- Flutter实现底部和顶部导航栏 2022-08-31
- 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
- 详解flutter engine 那些没被释放的东西 2022-12-04
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- Android实现轮询的三种方式 2023-02-17
