简体   繁体   English

UIImageView切换setContentMode随机EXEC_BAD_ACCESS

[英]UIImageView switching setContentMode random EXEC_BAD_ACCESS

I'm using an UIImageView and UIScrollView inside UIViewController to show images. 我在UIViewController中使用UIImageView和UIScrollView来显示图像。 Actual Size and Fit to Screen options available at the toolbar to let user switch between modes. 工具栏上的“实际大小”和“适合屏幕大小”选项可让用户在模式之间切换。 While switching between modes I am getting EXEC_BAD_ACCESS error randomly. 在两种模式之间切换时,我随机得到EXEC_BAD_ACCESS错误。 Randomly means I can switch to Actual Size mode to Fit to Screen modes copule of times. 随机意味着我可以切换到“实际大小”模式以适应屏幕模式。 When I hit one of them randomly application crashes. 当我碰到其中之一时,应用程序崩溃。

Here is the code that I am using if it wont help I may post the h and m files. 这是我正在使用的代码,如果它无法帮助我可以发布h和m文件。

        -(void)loadImage{

     NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
     NSString *filePath = [documentsDirectory stringByAppendingPathComponent:imgFilePath];

     imageView.image = [UIImage imageWithData: [NSData dataWithContentsOfFile:filePath]];

     imgLoaded = 1;

    }


    -(void)FitToScreen{

     if(imgLoaded<1) [self loadImage];

     if(currentState != STATE_IMGPLAYER_FULLSCREEN ){
      currentState = STATE_IMGPLAYER_FULLSCREEN;
     //[imageView setContentMode:UIViewContentModeCenter];
      [imageView setContentMode:UIViewContentModeScaleToFill];
      CGSize photoSize = imageView.frame.size;
      [scrollView setContentSize:photoSize];
     }
     // 

    }


    -(void)ActualSize{


     if(currentState != STATE_IMGPLAYER_ACTUAL_SIZE){

      currentState = STATE_IMGPLAYER_ACTUAL_SIZE;

      [imageView setContentMode:UIViewContentModeTopLeft];
      [scrollView setContentMode:UIViewContentModeCenter];

      CGSize photoSize = [imageView.image size];

      [scrollView setContentSize:photoSize];

     }

    }

-(IBAction)info_clicked:(id)sender 
{
 UIButton *button = (UIButton *)sender;


 if ([button tag] == BTN_FIT2SIZE) {

  [Button setEnabled:NO];
  [Button2 setEnabled:YES];

  [self ActualSize];

 } else if ([button tag] == BTN_FIT2SCREEN) {

  [Button setEnabled:YES];
  [Button2 setEnabled:NO];
  [self FitToScreen];

 }

 [button release];
}

Console Msg: 控制台消息:

Program received signal:  “EXC_BAD_ACCESS”.

Thanks for your help. 谢谢你的帮助。

A first quick guess is that maybe you aren't retaining the imageView or its image? 初步的猜测是您可能没有保留imageView或其图像? If you could post your stack trace and maybe the line where it crashes, it would be useful. 如果您可以发布堆栈跟踪以及崩溃的行,它将很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM