2012-06-12 98 views
0

1)我有一個UIViewUIImageView上,我加載圖片庫的圖片。我想知道如何將畫面「居中」在屏幕上,並確保寬高比不變。例如,如果我加載了處於橫向模式的圖片,如何確保圖片沒有在整個屏幕上延伸?我的應用程序正在使用肖像模式。UIImageView的頂部和設置大小

2)在同一視圖中,我想添加一個效果,即當用戶觸摸屏幕時,按鈕菜單淡出並再次按下時返回。我不確定那是什麼,我不能讓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"); 
} 

IBAction鏈接到tap gesture recognizer

+0

請發送一些代碼 –

回答

0

我的解決辦法

1)添加imgView.contentMode = UIViewContentModeScaleAspectFit;

2)像奧馬爾Abdelhafith說我加imgView.userInteractionEnabled = YES;,UITapGestureRecognizer對我來說就是它創建的故事板。

1

對於視圖中居中的UIImageView,你會做以下

//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; 

爲了增加點擊手勢識別器做以下

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

謝謝你,幫了我很多 –

+0

歡迎任何時間:)也請不要忘記接受答案,如果這是有幫助的:) –

+0

「2)」是有幫助的,有2個藝術問題的問題^ _ ^ –

相關問題