我的應用程序有兩個ViewController與NavigationController鏈接。第一個NavigationController有一個帶按鈕的視圖和一個帶標籤的視圖。這個視圖是一個循環旋轉菜單,它代表了我的主頁。視圖可以隨CGAffineTransformMakeRotation旋轉 - QuartzCore(顯然這是造成問題)在touchesMoved :.隱藏導航欄時位移/扭曲的按鈕(旋轉後)
我想隱藏導航欄只有在這種觀點,所以我用setNavigationBarHidden:YES上viewWillAppear中。然後在ViewWillDisappear上顯示吧。
在模擬器上,一切按預期工作,直到我旋轉第一個ViewController,當我旋轉然後點擊任何按鈕(轉到第二個ViewController)然後點擊返回(回到我的第一個ViewController),一切都會是distorted!
- 我試圖通過添加來解決該問題[self.view的setBounds:[[UIScreen mainScreen]界限]]; * [self.view SETFRAME:[[UIScreen mainScreen]界限]]; *在viewDidLoad中方法或ViweWillAppear, 問題仍然存在。
- 我試圖導航欄阿爾法在viewWillAppear中設置爲0和設置 它1 ViewWillDisappear,我試圖 self.navigationController.navigationBar.translucent = YES都 選項並沒有解決問題。
- 我試圖以編程方式設置視圖,按鈕和標籤的位置 in ViewWillAppear並且它不能解決問題。
- 我懷疑動畫,所以我刪除它,但它對問題沒有任何影響。
作爲初學者,我無法解決此問題,請幫忙!
ViewController.h(第一視圖控制器)
#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
ViewController.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];
}
我注意到,雖然從第一個ViewController翻譯到第二個,第一個視圖延伸(顯然NavigationBar是擠壓視圖)!它仍然被擠壓!...任何想法如何避免這種情況?每次我去第二個ViewController並回到第一個時,它會擠壓更多... – 2012-04-19 14:32:11