先添加到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.easck.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混编,所以.........
代码地址因为项目过大只上传了重要的代码文件。
最后还是声明一下,写这个纯属娱乐,请勿用作商业用途,否则后果自负。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。
注:相关教程知识阅读请移步到IOS开发频道。










