Ios 无法调用UIWebView上的所有函数

Ios 无法调用UIWebView上的所有函数,ios,objective-c,oop,Ios,Objective C,Oop,我试图在iOS上用setTransform转换UIWebView,我还试图用setHidden隐藏它 这些功能在当前设置中都不起作用,但loadRequest起作用;为什么会出现这种情况?如何使setTransform和setHidden工作 // ViewController.h @class EAGLView, ARUtils; @interface ViewController : ARViewController { UIWebView* webview; } @property

我试图在iOS上用
setTransform
转换
UIWebView
,我还试图用
setHidden
隐藏它

这些功能在当前设置中都不起作用,但
loadRequest
起作用;为什么会出现这种情况?如何使
setTransform
setHidden
工作

// ViewController.h
@class EAGLView, ARUtils;
@interface ViewController : ARViewController {
    UIWebView* webview;
}
@property (assign) UIWebView* webview;

// ViewController.mm
@synthesize webview;

-(void)viewDidLoad{
    [super viewDidLoad];
    webview = [[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
    [self.view addSubview:webview];
}

// EAGLView.mm
ViewController* uic;
for( UIView* next = [self superview];  next; next = next.superview){
    UIResponder* nextResponder = [next nextResponder];
    if([nextResponder isKindOfClass:[ViewController class]]){
        uic = (ViewController*)nextResponder;
    }
}

// These functions don't work:
[[[uic webview] layer] setTransform:matrix];
[[uic webview] setHidden:YES];

// And this one does:
[[uic webview] loadRequest:requestObj];

提前谢谢

您是否正确导入了QuartzCore标头?有时我想知道为什么我的代码不起作用,然后我意识到我忘了导入这个头

#import <QuartzCore/QuartzCore.h>
您可以在此处找到有关动画(以及层备份//层托管视图)的非常有用的信息:

大多数UIKit类(如
UIWebView
)只能从主线程安全使用。当您在后台线程上时,可以使用GCD在主队列(与主线程关联)上执行阻塞:


是的,我已经这样做了,我也有那个问题,但至少那个给了我一个错误…你在使用层备份视图吗?如果是这样,您就不能直接访问transform属性;但是我用更多的信息更新了我的问题。哦,我刚刚看到,你应该添加:[webview SetWantLayer:是]然后你可以在你的视图中使用层和核心动画。我尝试了你的解决方案,但没有成功,调用
web.layer.transform=aTransform
也会生成错误。而且
[webview setWantsLayer:YES]
也不起作用,因为webview没有名为
setWantsLayer
的函数/属性。您确定设置转换时
webview
不是
nil
吗?是的,因为我可以调用函数
[[uic webview]loadRequest:requestObj]这个方法很好用,它会显示在屏幕上,但不会被转换。你到底在哪里调用这些方法?您是否可能在后台线程上?我正在Vuforia框架的
renderFrameQCAR
函数中调用这些函数。我真的不知道Vuforia如何处理它的线程
EAGLView
AR\u EAGLView
的扩展,这是该类的源代码:当您使用任何UIKit类时,您必须位于主线程/队列上。当然,有些事情也可能在后台线程中“碰巧”工作,但不能保证。使用
dispatch\u async(dispatch\u get\u main\u queue(),^{//your code here})
CATransform3D matrix = CATransform3DRotate(web.layer.transform, 1.14, 0.0, 1.0, 0.0);

CABasicAnimation *animTransform = [CABasicAnimation animationWithKeyPath:@"transform"];
animTransform.fromValue = [NSValue valueWithCATransform3D:web.layer.transform];
animTransform.toValue = [NSValue valueWithCATransform3D: matrix];

animTransform.duration = 1;  // arbitrary chosen time
animTransform.autoreverses = NO; // we don't want animation to go back from beginning when ended
animTransform.repeatCount = 0;
animTransform.delegate=self;  // optional, you can use a delegate to start methods when the animation ends


// real change of the values, because the CABasicAnimation is only visual
web.layer.transform = aTransform;

// and start the animation
[web.layer  addAnimation:animTransform forKey:nil]; 
dispatch_async(dispatch_get_main_queue(), ^{
    //your code here
});