我的应用程序有两个与 NavigationController 链接的 ViewController。第一个 NavigationController 有一个带有按钮的视图和一个带有标签的视图。这个视图是一个圆形的旋转菜单,它代表我的主页。视图可以通过 touchesMoved: 上的 CGAffineTransformMakeRotation - QuartzCore (显然它导致问题)旋转。
我只想在这个视图中隐藏 NavigationBar,所以我在 ViewWillAppear 上使用了setNavigationBarHidden :YES。然后在ViewWillDisappear上显示栏。
在模拟器上,一切都按预期工作,直到我旋转第一个 ViewController,当我旋转然后单击任何按钮(转到第二个 ViewController)然后单击返回(返回到我的第一个 ViewController),一切都将被扭曲!。
- 我试图通过添加[self.view setBounds:[[UIScreen mainScreen]bounds]];来解决这个问题。*[self.view setFrame:[[UIScreen mainScreen]bounds]];* 在ViewDidLoad方法或ViweWillAppear中,问题仍然存在。
- 我尝试在 ViewWillAppear 中将 NavigationBar alpha 设置为 0,并在ViewWillDisappear 上将其设置为 1,然后我尝试了self.navigationController.navigationBar.translucent = YES 两个选项都没有解决问题。
- 我尝试在ViewWillAppear中以编程方式设置视图、按钮和标签位置,但并没有解决问题。
- 我怀疑动画,所以我删除了它,但它对问题没有任何影响。
作为初学者,我无法解决这个问题,请帮助!
ViewController.h(第一个 ViewController)
#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
视图控制器.m
#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];
}