Ios 如何使图像(不)可点击?

Ios 如何使图像(不)可点击?,ios,uiimageview,Ios,Uiimageview,我正在写一个显示一些图片的应用程序,当用户点击图片时,它会调用一些函数 在纵向模式下,我将图像设置为可单击以大规模预览: [imgv addTarget:self action:@selector(funShowPhoto) forControlEvents:UIControlEventTouchUpInside]; 我想在横向模式下跳过这个函数,我尝试了这个,但是函数仍然调用,我应该怎么做 [imgv addTarget:self action:nil forControlEvents:UI

我正在写一个显示一些图片的应用程序,当用户点击图片时,它会调用一些函数

在纵向模式下,我将图像设置为可单击以大规模预览:

[imgv addTarget:self action:@selector(funShowPhoto) forControlEvents:UIControlEventTouchUpInside];
我想在横向模式下跳过这个函数,我尝试了这个,但是函数仍然调用,我应该怎么做

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

只需在
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

  }
}

您可以在前面给出的Panayot Panayotov代码中添加:

imgv.userInteractionEnabled = NO;

这样,您就不必更改操作。

如果横向设置userInteractionEnabled设置为
NO
else
YES
,则在设备方向更改时执行此操作。
- (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
{


}