2012-06-12 2 views
0

1) UIImageView이있는 UIView을 가지고 있습니다. 이미지 갤러리에서 사진을로드합니다. 나는 화면에 그림을 "중앙에 배치"하여 종횡비가 변경되지 않도록하는 방법을 알고 싶습니다. 예를 들어 풍경 모드의 사진을로드하는 경우 화면 전체에 사진이 늘어나지 않도록하려면 어떻게해야합니까? 내 앱이 세로 모드로 작동합니다.UIImageView를 맨 위에 놓고 크기를 설정

2) 동일한보기에서 사용자가 화면에 닿을 때 botton 메뉴가 사라지고 다시 누르면 효과가 추가됩니다. 그게 뭐라 불리는 지 모르겠고 나는 tap gesture recognizer을 사용할 수 없었습니다.

편집 :

나는 페이지로드

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
xlabel = [[UILabel alloc] initWithFrame:self.setLablePosition]; 
xlabel.backgroundColor = [UIColor clearColor]; 

imgView.image = self.appDelegate.theImg; // now the image is put on a UIImageView that is "full screen" 
xlabel.text = @"Some text"; 
[imgView addSubview:xlabel]; 
// Do any additional setup after loading the view. 
} 

UIImageView을 설정하고 Tap gesture에 관해서 :

-(IBAction)screenTapped{ 
NSLog(@"screen Tapped"); 
} 

IBActiontap gesture recognizer에 연결되어 있습니다.

+0

일부 코드를 게시하십시오 –

답변

0

내 솔루션은

1) imgView.contentMode = UIViewContentModeScaleAspectFit;를 추가 한 다음 작업을 수행 탭 제스처 인식기를 추가하려면 다음

//First give imgView the correct size 
//You may need to divide the size by some constant if the image is too big 
imgView.frame = CGRectMake(0, 0, self.appDelegate.theImg.size.width, self.appDelegate.theImg.size.width); 
//Then center it 
imgView.center = self.view.center; 

할 것

2) Omar Abdelhafith가 내가 0을 추가했다고 말했습니다., 나를위한 UITapGestureRecognizer은 스토리 보드를 만들었습니다.

1

뷰에있는 UIImageView를 중심으로 들어 당신은

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(screenTapped)]; 
//By deafualt interaction is disabled 
imgView.userInteractionEnabled = YES; 
[imgView addGestureRecognizer:recognizer]; 
+0

감사합니다. 내게 많은 도움을주었습니다. –

+0

언제든지 환영합니다. :) 도움이 되었다면 대답을 수락하지 마십시오. :) –

+0

"2)"는 도움이되었습니다.^_ ^ –

관련 문제