I am trying to get a UIWebView to work in my Unity project. My app always runs in Landscape_Left. I have that part all working. It is rotated and looks fine.
I am now trying to add a Back button to the upper left corner of the view. I will show the code below. If I comment out this line:
[overlayWindow setTransform:transform];
and this line:
webView.center = overlayWindow.center;
then the button starts working, BUT the view is no longer rotated like I want it to be.
If I leave those lines in then everything is rotated like I want, but the button stops working. I let you know that to show that the rest of the set up for the button is correct.
You will notice that I have the dumpView code in there. After the following code I have included the dumpView output so maybe that will help someone help me figure this out.
You will notice that my button is a child of the UIWebViewScrollView. I also tried putting it one layer above that and that does not help.
Here is the code that is relevant:
- (void)backButtonClick
{
overlayWindow.hidden = YES;
[self dealloc];
}
void dumpView(UIView* aView, NSString* indent) {
if (aView) {
NSLog(@"%@%@", indent, aView); // dump this view
if (aView.subviews.count > 0) {
NSString* subIndent = [[NSString alloc] initWithFormat:@"%@%@",
indent, ([indent length]/2)%2==0 ? @"| " : @": "];
for (UIView* aSubview in aView.subviews) dumpView( aSubview, subIndent );
[subIndent release];
}
}
}
- (id)initWithGameObjectName:(const char *)gameObjectName_
{
self = [super init];
CGRect bounds = [[UIScreen mainScreen] bounds];
orientedFrame = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.height, bounds.size.width);
float scale = 480 / bounds.size.height;
overlayWindow = [[UIWindow alloc] initWithFrame:bounds];
float angle = M_PI_2;
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
[overlayWindow setTransform:transform];
webView = [[UIWebView alloc] initWithFrame:orientedFrame];
webView.delegate = self;
webView.hidden = NO;
webView.center = overlayWindow.center;
UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(5, 5, 200 * scale, 100 * scale)] autorelease];
button.backgroundColor = [UIColor orangeColor];
[button setTitle:@"Back" forState:UIControlStateNormal];
button.opaque = YES;
[button addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
if (webView.subviews.count > 0)
{
[webView.subviews[0] addSubview:button];
[webView.subviews[0] bringSubviewToFront:webView];
}
[overlayWindow addSubview:webView];
[overlayWindow makeKeyAndVisible];
dumpView(overlayWindow, @"dumpView:");
gameObjectName = [[NSString stringWithUTF8String:gameObjectName_] retain];
return self;
}
2013-05-14 17:06:57.910 vigilante[5995:907] dumpView:<UIWindow: 0xf30ca40; frame = (-128 128; 1024 768); transform = [0, 1, -1, 0, 0, 0]; layer = <UIWindowLayer: 0xf30ca00>>
2013-05-14 17:06:57.911 vigilante[5995:907] dumpView:| <UIWebView: 0xf30c4e0; frame = (-128 128; 1024 768); layer = <CALayer: 0xf30c460>>
2013-05-14 17:06:57.912 vigilante[5995:907] dumpView:| : <_UIWebViewScrollView: 0xf3076e0; frame = (0 0; 1024 768); clipsToBounds = YES; autoresize = H; gestureRecognizers = <NSArray: 0xf3074d0>; layer = <CALayer: 0xf307d20>; contentOffset: {0, 0}>
2013-05-14 17:06:57.914 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf306380; frame = (0 0; 10 10); transform = [-1, 0, -0, -1, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf306350>>
2013-05-14 17:06:57.915 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf306410; frame = (0 0; 10 10); transform = [0, 1, -1, 0, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf3063e0>>
2013-05-14 17:06:57.916 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf3064a0; frame = (0 0; 10 10); transform = [0, -1, 1, 0, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf306470>>
2013-05-14 17:06:57.916 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf306670; frame = (0 0; 10 10); alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf306500>>
2013-05-14 17:06:57.917 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf306700; frame = (-4.5 4.5; 10 1); transform = [0, 1, -1, 0, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf3066d0>>
2013-05-14 17:06:57.919 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf306790; frame = (-4.5 4.5; 10 1); transform = [0, -1, 1, 0, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf306760>>
2013-05-14 17:06:57.919 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf306820; frame = (0 0; 1 10); transform = [-1, 0, -0, -1, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf3067f0>>
2013-05-14 17:06:57.921 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf3069f0; frame = (0 0; 1 10); alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf306880>>
2013-05-14 17:06:57.922 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf306a80; frame = (0 762; 1024 6); alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf306a50>>
2013-05-14 17:06:57.923 vigilante[5995:907] dumpView:| : | <UIImageView: 0xf306c50; frame = (0 0; 1024 6); transform = [-1, 0, -0, -1, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xf306ae0>>
2013-05-14 17:06:57.924 vigilante[5995:907] dumpView:| : | <UIWebBrowserView: 0x3acc200; frame = (0 0; 1024 768); gestureRecognizers = <NSArray: 0xf309640>; layer = <UIWebLayer: 0xf30ba90>>
2013-05-14 17:06:57.925 vigilante[5995:907] dumpView:| : | <UIButton: 0xf303ce0; frame = (5 5; 93.75 46.875); layer = <CALayer: 0xf303cb0>>