Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Hotshot10101 · May 14, 2013 at 11:08 PM · iosbuttonlandscape

UIButton not working when parent is rotated

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>>
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Hotshot10101 · May 22, 2013 at 07:57 PM

I never was able to get the rotated button to work, so I ended up just making the window smaller so it would leave room at the top and have a button on the Unity screen that is behind this.

This actually works a lot better as I can do all the button processing in Unity rather than having to do it in Obj-C.

It may not work well for others, but it works great for my project.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Screenshot certain layers so it doesn't show GUI Button on the image?? 0 Answers

Unity iOS CompileC error while building through Xcode 1 Answer

Is it possible to trigger the iPad screenshot functionality from an application without button combination? 0 Answers

How can I limit my app to specific orientations? 2 Answers

GUI.Button lags on iPhone 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges