2012-10-08 3 views
1

아울렛에 연결된 xib에 MapView가 있습니다. 나는 초상화와 풍경을위한 코드로 프레임을 설정했다. 프레임이 정확하지만 출력이 잘못되었습니다. 왜?mapView의 프레임이 잘못되었습니다.

@interface MapViewController : UIViewController <MKMapViewDelegate>{ 

    } 

    @property (nonatomic, strong)UIImageView * imageView; 
    @property (nonatomic, strong)IBOutlet UIButton * buttonHome; 
    @property (nonatomic, strong)IBOutlet UIButton * buttonMap; 
    @property (nonatomic, strong)IBOutlet UIButton * buttonFavorites; 
    @property (nonatomic, strong)IBOutlet UILabel * labelTitle; 
    @property (nonatomic, strong)IBOutlet MKMapView *mapView; 

및 MapViewController.m

@implementation MapViewController 

    @synthesize imageView; 
    @synthesize buttonFavorites; 
    @synthesize buttonHome; 
    @synthesize buttonMap; 
    @synthesize labelTitle; 
    @synthesize mapView; 

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    { 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

-(void) layoutPortrait { 

self.imageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar_V.png"]]; 
self.imageView.frame= CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, 80); 
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
self.labelTitle.frame =CGRectMake(14, 83, 121, 54); 
self.buttonFavorites.frame= CGRectMake(109, 485, 33, 33); 
self.buttonHome.frame =CGRectMake(14, 485, 33, 33); 
self.buttonMap.frame=CGRectMake(61, 485, 33, 33); 
self.mapView.frame = CGRectMake(0, 140, 320, 310); 


} 

-(void) layoutLandscape { 

self. imageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar_O.png"]]; 
self.imageView.frame= CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y,self.view.bounds.size.width,70); 
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
self.labelTitle.frame =CGRectMake(20,72,140,48); 

self.buttonFavorites.frame= CGRectMake(107,237,33,33); 
self.buttonHome.frame =CGRectMake(11,237,33,33); 
self.buttonMap.frame=CGRectMake(59,237,33,33); 
self.mapView.frame = CGRectMake(201,65,367,227); 


} 


- (void)viewDidLoad 
{ 
[super viewDidLoad]; 


UIInterfaceOrientation deviceOrientation= self.interfaceOrientation; 

if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) { 
    [self layoutPortrait]; 

} 
else if (deviceOrientation== UIInterfaceOrientationLandscapeRight){ 
    [self layoutLandscape]; 

} 
else if (deviceOrientation==UIInterfaceOrientationLandscapeLeft){ 

    [self layoutLandscape]; 

} 

[self.view addSubview:self.imageView]; 
[self.view addSubview:self.mapView]; 
[self.view addSubview:self.labelTitle]; 
[self.view addSubview:self.buttonHome]; 
[self.view addSubview:self.buttonMap]; 
[self.view addSubview:self.buttonFavorites]; 


self.mapView.delegate=self; 
} 

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice]orientation]; 

if(self.imageView){ 
    [self.imageView removeFromSuperview]; 

} 

if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) { 
    [self layoutPortrait]; 

} 
else if (deviceOrientation== UIInterfaceOrientationLandscapeRight){ 
    [self layoutLandscape]; 

} 
else if (deviceOrientation==UIInterfaceOrientationLandscapeLeft){ 

    [self layoutLandscape]; 

} 

[self.view addSubview:self.mapView]; 
[self.view addSubview:self.labelTitle]; 
[self.view addSubview:self.imageView]; 
[self.view addSubview:self.buttonFavorites]; 
[self.view addSubview:self.buttonHome]; 
[self.view addSubview:self.buttonMap]; 


} 

내가 뭘 잘못하고있다 :

이 MapViewController.h 내 코드는?

답변

1

몇 가지 :

1) 수행 당신에게 XIB 파일에 당신의 MKMapView에 자동으로 크기가 있나요? 코드에서 수행중인 작업을 방해 할 수 있습니다.

2) 회전 논리는 viewDidLoad이 아닌 올바른 위치에서 처리해야합니다. UIViewController Class reference에서 부품 번호 회전보기 처리을 확인하면 코드를 넣을 위치를 알 수 있습니다.

+0

자동 크기가 없습니다. Xcode 버전 4.5 있고 그것을 찾을 수 없습니다. –