2014-05-22 50 views
0

我寫一個應用程序,顯示一些圖片,它會調用一些功能,當用戶點擊肖像模式圖像如何使圖像(un-)可點擊?

,我設置圖像點擊預覽它在大尺度:

[imgv addTarget:self action:@selector(funShowPhoto) forControlEvents:UIControlEventTouchUpInside]; 

我想在橫向模式下跳過這個功能,我試過這個但功能還在調用,我該怎麼辦?

[imgv addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; 

回答

0

就在您添加條件funShowPhoto方法

-(void)funShowPhoto 
{ 
// check if device is in portrait orientation 
    if([[UIDevice currentDevice]orientation] == UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown) 
    { 

    // run your code here device is in Portrait Mode 

    } 
} 
0

您可以添加到先前給出的班乃特·帕納約多芬代碼:

imgv.userInteractionEnabled = NO; 

這樣,你就不必改變行動。

+0

如果橫向將userInteractionEnabled設置爲'NO'else'YES',則在設備方向發生變化時執行此操作。 – Hemang

0
- (void)viewDidLoad 
{ 

    UIButton *button_barcord = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // .....button_faves.... 
    [button_barcord addTarget:self 
         action:@selector(bMethod:) 
      forControlEvents:UIControlEventTouchUpInside]; 
    [button_barcord setBackgroundImage:[UIImage imageNamed:@"yourimag.png"] forState:UIControlStateNormal]; 

    [button_barcord setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 

    button_barcord.frame = CGRectMake(240,75,54,54); 
    [self.view addSubview:button_barcord]; 
    [super viewDidLoad]; 
} 
-(IBAction)bMethod:(id)sender 
{ 


}