0

我正在尝试UIWebView在 iOS 上转换 asetTransform并且我也尝试使用setHidden.

这些功能在当前设置loadRequest中都不起作用,但可以;为什么会这样,我怎样才能得到setTransformsetHidden工作?

// 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];

提前致谢!

4

2 回答 2

2

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

dispatch_async(dispatch_get_main_queue(), ^{
    //your code here
});
于 2013-03-18T15:30:45.503 回答
0

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

#import <QuartzCore/QuartzCore.h>

编辑 :

你可以试试这个代码,它适用于 Layer-Backed view :

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]; 

您可以在此处找到有关动画(和支持图层的 // 图层托管视图)的非常有用的信息:https ://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/CreatingBasicAnimations/CreatingBasicAnimations.html #//apple_ref/doc/uid/TP40004514-CH3-SW1

于 2013-03-18T10:54:05.493 回答