Ios5 隐藏导航栏时按钮移位/变形(旋转后)
我的应用程序有两个与NavigationController链接的ViewController。第一个NavigationController有一个带按钮的视图和一个带标签的视图。此视图是一个圆形旋转菜单,它表示我的主页。视图可以在TouchsMoved:上使用CGAffineTransformMakeRotation-QuartzCore进行旋转(显然是它导致了问题) 我只想在这个视图中隐藏导航栏,所以我使用了setNavigationBarHidden:YES on ViewWillDisplay。然后在视图上显示该条将消失 在模拟器上,一切都按预期工作,直到我旋转第一个ViewController,当我旋转时,然后单击任何按钮(转到第二个ViewController),然后单击上一步(回到第一个ViewController),一切都将正常Ios5 隐藏导航栏时按钮移位/变形(旋转后),ios5,rotation,uinavigationbar,quartz-core,Ios5,Rotation,Uinavigationbar,Quartz Core,我的应用程序有两个与NavigationController链接的ViewController。第一个NavigationController有一个带按钮的视图和一个带标签的视图。此视图是一个圆形旋转菜单,它表示我的主页。视图可以在TouchsMoved:上使用CGAffineTransformMakeRotation-QuartzCore进行旋转(显然是它导致了问题) 我只想在这个视图中隐藏导航栏,所以我使用了setNavigationBarHidden:YES on ViewWillDisp
是的,我解决了问题…当NavigationController是否隐藏时,主视图的自动调整大小会挤压我的子视图。所以我添加了self.view.autoresizesSubviews=NO;查看加载,问题就解决了。我注意到,当从第一个ViewController转换到第二个ViewController时,第一个视图会拉伸(显然导航栏正在压缩视图)!它仍然被挤压着!…你知道如何避免这种情况吗?每次我转到第二个ViewController并返回到第一个,它都会挤压更多…你不知道我对这个答案有多感激。这也可以在属性检查器下的interface builder中完成。只需取消选中“自动调整子视图大小”框。
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ViewController : UIViewController
@property (nonatomic, strong) IBOutlet UIView *aView;
@property (nonatomic, strong) IBOutlet UIView *bView;
@property (nonatomic, strong) IBOutlet UIButton *bimg1;
…
@property (strong, nonatomic) IBOutlet UILabel *label1;
…
-(void) rotateTo:(CGFloat)x andY:(CGFloat)y;
@end
#import "ViewController.h"
@implementation ViewController
@synthesize aView = _aView;
…
@synthesize bimg1 = _bimg1;
…
@synthesize label1 = _label1;
…
static inline double toradians (double degrees) {
return degrees * M_PI/180;
}
-(void)viewDidLoad {
![enter image description here][1][super viewDidLoad];
//Set text font
[_label1 setFont:[UIFont fontWithName:@"Consolas" size:16]];
…
[self.view setBounds:[[UIScreen mainScreen]bounds]];
[self.view setFrame:[[UIScreen mainScreen]bounds]];
}
-(void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBar.hidden = YES;
printf("Aview x: %f | Aview y: %f \n",self.aView.frame.origin.x, self.aView.frame.origin.y);
printf("Aview width: %f | Aview height: %f \n",self.aView.frame.size.width, self.aView.frame.size.height);
}
-(void)viewWillDisappear:(BOOL)animated {
self.navigationController.navigationBar.hidden = NO;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint LastTouchPoint = [touch locationInView:self.view];
CGFloat LasTouchx = LastTouchPoint.x;
CGFloat LasTouchy = LastTouchPoint.y;
CGPoint CenterPoint = self.view.center;
CGFloat x = LasTouchx - CenterPoint.x;
[self rotateTo:x andY:y];
}
-(void) rotateTo:(CGFloat)x andY:(CGFloat)y {
CGFloat angle = x/y;
angle = atan(angle);
angle = angle * 360/M_PI;
angle *= 0.0174532925;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:1];
self.aView.transform=CGAffineTransformMakeRotation(-angle);
self.bView.transform=CGAffineTransformMakeRotation(-angle);
self.bimg1.transform=CGAffineTransformMakeRotation(angle);
self.bimg2.transform=CGAffineTransformMakeRotation(angle);
self.bimg3.transform=CGAffineTransformMakeRotation(angle);
self.bimg4.transform=CGAffineTransformMakeRotation(angle);
self.label1.transform=CGAffineTransformMakeRotation(angle);
self.label2.transform=CGAffineTransformMakeRotation(angle);
self.label3.transform=CGAffineTransformMakeRotation(angle);
self.label4.transform=CGAffineTransformMakeRotation(angle);
[UIView commitAnimations];
}
- (void)viewDidUnload
{
[self setBimg1:nil];
…
[self setAView:nil];
[self setBView:nil];
[super viewDidUnload];
}