<i id='IeuPP'><tr id='IeuPP'><dt id='IeuPP'><q id='IeuPP'><span id='IeuPP'><b id='IeuPP'><form id='IeuPP'><ins id='IeuPP'></ins><ul id='IeuPP'></ul><sub id='IeuPP'></sub></form><legend id='IeuPP'></legend><bdo id='IeuPP'><pre id='IeuPP'><center id='IeuPP'></center></pre></bdo></b><th id='IeuPP'></th></span></q></dt></tr></i><div id='IeuPP'><tfoot id='IeuPP'></tfoot><dl id='IeuPP'><fieldset id='IeuPP'></fieldset></dl></div>

  • <legend id='IeuPP'><style id='IeuPP'><dir id='IeuPP'><q id='IeuPP'></q></dir></style></legend>

        <bdo id='IeuPP'></bdo><ul id='IeuPP'></ul>
      <tfoot id='IeuPP'></tfoot>

        <small id='IeuPP'></small><noframes id='IeuPP'>

        UIButtons 在自动旋转设置框架后不响应触摸

        时间:2023-05-18
        <tfoot id='xD7Wn'></tfoot>

        • <bdo id='xD7Wn'></bdo><ul id='xD7Wn'></ul>
          <legend id='xD7Wn'><style id='xD7Wn'><dir id='xD7Wn'><q id='xD7Wn'></q></dir></style></legend>

            1. <small id='xD7Wn'></small><noframes id='xD7Wn'>

                <tbody id='xD7Wn'></tbody>
                  <i id='xD7Wn'><tr id='xD7Wn'><dt id='xD7Wn'><q id='xD7Wn'><span id='xD7Wn'><b id='xD7Wn'><form id='xD7Wn'><ins id='xD7Wn'></ins><ul id='xD7Wn'></ul><sub id='xD7Wn'></sub></form><legend id='xD7Wn'></legend><bdo id='xD7Wn'><pre id='xD7Wn'><center id='xD7Wn'></center></pre></bdo></b><th id='xD7Wn'></th></span></q></dt></tr></i><div id='xD7Wn'><tfoot id='xD7Wn'></tfoot><dl id='xD7Wn'><fieldset id='xD7Wn'></fieldset></dl></div>

                  本文介绍了UIButtons 在自动旋转设置框架后不响应触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  您好,在我的应用程序中,我将一些 uiButtons 作为子视图添加到如下图所示的视图中.alt text http://img99.imageshack.us/img99/5244/portraitc.png

                  Hello in my app i have some uiButtons added as subviews to a view like in the picture below. alt text http://img99.imageshack.us/img99/5244/portraitc.png

                  当用户横向旋转手机时,视图和按钮的位置必须改变为:alt text http://img193.imageshack.us/img193/5931/landscapeq.png

                  when the user rotates the phone in landscape the views and buttons must change position to this: alt text http://img193.imageshack.us/img193/5931/landscapeq.png

                  最初,当视图处于纵向模式时,按钮会响应触摸.如果我倾斜手机按钮移动,一切看起来都像第二张图片一样,按钮响应触摸.如果我将手机倾斜回纵向模式,按钮会向后移动,它们看起来不错,但对触摸没有反应.如果我改回横向按钮工作...

                  initially when the view is in portrait mode the buttons respond to touches. If i tilt the phone the buttons move, everything looks ok like in the second image and the buttons respond to touches. If i tilt the phone back to portrait mode, the buttons move back they look ok but they don't respond to touches. If i change back to landscape the buttons work...

                  我的按钮是这样创建的:

                  my buttons are created like this:

                  nextNewsP = [[UIButton alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 40, 10, 25, 25)];
                  [nextNewsP setImage:[UIImage newImageFromResource:@"next_arrow.png"] forState:UIControlStateNormal];
                  [nextNewsP addTarget:self action:@selector(nextNewsAction:) forControlEvents:UIControlEventTouchUpInside];
                  [nextNewsP setShowsTouchWhenHighlighted:TRUE];
                  [bottomTools addSubview:nextNewsP];
                  [nextNewsP release];
                  
                  previousNewsP = [[UIButton alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 85, 10, 25, 25)];
                  [previousNewsP setImage:[UIImage newImageFromResource:@"previous_arrow.png"] forState:UIControlStateNormal];
                  [previousNewsP addTarget:self action:@selector(previousNewsAction:) forControlEvents:UIControlEventTouchUpInside];
                  [previousNewsP setShowsTouchWhenHighlighted:TRUE];
                  [bottomTools addSubview:previousNewsP];
                  [previousNewsP release];
                  

                  bottomTools 是一个视图,也可以作为子视图添加,如下所示:

                  bottomTools is a view and is added also as a subview like this:

                  [self.view addSubview:bottomTools];
                  [bottomTools release];
                  

                  我的 shouldAutorotateToInterfaceOrientation 函数如下所示:

                  and my shouldAutorotateToInterfaceOrientation function looks like this:

                  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
                  
                  
                      [UIView beginAnimations:@"moveViews" context: nil];
                  
                  
                      if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
                      {
                          NSLog(@"set frames for portrait");
                          closeView.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 30, 2, 23, 25);
                          newsInfo.frame = CGRectMake(10, 10, [[UIScreen mainScreen] bounds].size.width - 10, 22);
                          internetActivityIndicator.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 55, 5, 18, 18);
                          industryLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width/2.0 - [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width/2, 3, [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width, 22);
                          bottomTools.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-40, [[UIScreen mainScreen] bounds].size.width, 40);
                          nextNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 40, 10, 25, 25);
                          previousNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 85, 10, 25, 25);
                      }
                      else
                      {
                          NSLog(@"set frames for landscape");
                          closeView.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 30, 2, 23, 25);
                          newsInfo.frame = CGRectMake(10, 10, [[UIScreen mainScreen] bounds].size.height - 10, 22);
                          internetActivityIndicator.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 55, 5, 18, 18);
                          industryLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height/2.0 - [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width/2, 3, [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width, 22);
                          bottomTools.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.width-40, [[UIScreen mainScreen] bounds].size.height, 40);
                          nextNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 40, 10, 25, 25);
                          previousNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 85, 10, 25, 25);
                      }
                  
                      [UIView commitAnimations];
                  
                  return YES;
                  

                  }

                  你有没有遇到过类似的问题?先感谢您,索林

                  did you ever had a similar problem? thank you in advance, Sorin

                  推荐答案

                  我认为你的问题是在你的框架调整.我的直觉告诉我它与 shouldAutorotateToInterfaceOrientation 内部的逻辑有关,因为这发生在实际完成旋转之前.尝试按照这篇文章中的方法计算你的数学,看看是否有帮助.

                  I think your problem is in your frame adjustment. My gut tells me it has something to do with the logic being inside shouldAutorotateToInterfaceOrientation because that happens before the rotation is actually done. Try doing your math the way they do it in this article and see if that helps.

                  这篇关于UIButtons 在自动旋转设置框架后不响应触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:旋转 UIBarButtonItem 下一篇:UINavigationBar 旋转和自动布局

                  相关文章

                • <legend id='UnBng'><style id='UnBng'><dir id='UnBng'><q id='UnBng'></q></dir></style></legend>
                • <tfoot id='UnBng'></tfoot>

                  <small id='UnBng'></small><noframes id='UnBng'>

                  1. <i id='UnBng'><tr id='UnBng'><dt id='UnBng'><q id='UnBng'><span id='UnBng'><b id='UnBng'><form id='UnBng'><ins id='UnBng'></ins><ul id='UnBng'></ul><sub id='UnBng'></sub></form><legend id='UnBng'></legend><bdo id='UnBng'><pre id='UnBng'><center id='UnBng'></center></pre></bdo></b><th id='UnBng'></th></span></q></dt></tr></i><div id='UnBng'><tfoot id='UnBng'></tfoot><dl id='UnBng'><fieldset id='UnBng'></fieldset></dl></div>

                        <bdo id='UnBng'></bdo><ul id='UnBng'></ul>