0

我是新的目标c。如何获取上传到服务器上的图像是横向模式还是纵向模式iphone

我有两个probelms。

我想要做的是显示像iphone galary这样的图像。我正在使用相同的滚动视频。我尝试过在很多帖子中使用fgalary和其他提及的galary,但是他们不是按照我的要求,因为我将不得不做很多定制。

//修改的注释

我想要做的就是在portrate模式在不同的帧大小采取类似CGRectMake(0,0,243,314),并显示图像,如果拍摄图像在横向模式下然后显示它在像CGRectMake(0,0,300,200)等单独的框架中。所有的图像都在服务器上上传,因为之前我在同一帧中显示所有图像,所以图像看起来很舒服,所以我正在像这样做。

我甚至试图从服务器获取图像加载的高度和宽度,如下面的代码所示,但即使不适用于从服务器加载的图像。请建议我一些更好的方法来解决我的问题。

我的代码

-(void)viewWillAppear:(BOOL)animated 
{ 


//new code 
float newWidth = 320 * [memoryData.memoryItemData count]; 
mailScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 380)]; 
[mailScrollView setContentSize:CGSizeMake(newWidth, 380)]; 
[mailScrollView setPagingEnabled:YES]; 
[mailScrollView setShowsHorizontalScrollIndicator:NO]; 
int xcoordinate = 0; 
int totalWidth,reminaderWidth; 
for(int x=0;x<[memoryData.memoryItemData count];x++){ 
    currentItem = x; 
    memoryItems *dataItem = (memoryItems*)[memoryData.memoryItemData objectAtIndex:currentItem]; 
    UIView *newImageView = [[UIView alloc] init]; 
    UIImageView *displayCurrentImage = [[UIImageView alloc] init]; 
    UIImageView *DescriptionView = [[UIImageView alloc] init]; 

    //for loading image using NYXProgressiveImageView 
    //[displayCurrentImage loadImageAtURL:[NSURL URLWithString:dataItem.memoeryItemFullUrl]]; 

    //for lading image using UIImageView+WebCache.h 
    [displayCurrentImage setImageWithURL:[NSURL URLWithString:dataItem.memoeryItemFullUrl]]; 

    UITextView *descriptionText = [[UITextView alloc] init]; 
    UILabel *dateLabel= [[UILabel alloc] init]; 
    UILabel *titleLabel= [[UILabel alloc] init]; 
    //for flip image 
    UIButton *flipBtnImg = [UIButton buttonWithType:UIButtonTypeCustom]; 
    UIButton *flipBtnCmt = [UIButton buttonWithType:UIButtonTypeCustom]; 
    displayCurrentImage.userInteractionEnabled = YES; 
    DescriptionView.userInteractionEnabled = YES; 
    NSLog(@"height of data %f and width of image %f",displayCurrentImage.image.size.height,displayCurrentImage.image.size.width); 
    if(displayCurrentImage.image.size.width < displayCurrentImage.image.size.height){        xcoordinate=xcoordinate+38; 
     flipBtnImg.frame = CGRectMake(208, 280, 30, 30); 
     flipBtnCmt.frame = CGRectMake(208, 280, 30, 30); 
     dateLabel.frame = CGRectMake(10, 10, 230, 20);    
     titleLabel.frame = CGRectMake(10, 35, 230, 30); 
     descriptionText.frame = CGRectMake(10, 70, 230, 100); 
     newImageView.frame = CGRectMake(xcoordinate, 22, 243, 314); 
     displayCurrentImage.frame = CGRectMake(0, 0, 243, 314); 
     DescriptionView.frame = CGRectMake(0, 0, 243, 314);     
     totalWidth = 243; 
     reminaderWidth = 39;       
    }else{     
     xcoordinate=xcoordinate+10; 
     flipBtnImg.frame = CGRectMake(265, 165, 30, 30); 
     flipBtnCmt.frame = CGRectMake(265, 165, 30, 30); 
     dateLabel.frame = CGRectMake(10, 10, 290, 20); 
     titleLabel.frame = CGRectMake(10, 35, 290, 20); 
     descriptionText.frame = CGRectMake(10, 60, 290, 100); 
     newImageView.frame = CGRectMake(xcoordinate, 80, 300, 200); 
     displayCurrentImage.frame = CGRectMake(0, 0, 300, 200); 
     DescriptionView.frame = CGRectMake(0, 0, 300, 200); 
     totalWidth = 300; 
     reminaderWidth= 10;     
    } 
    //for image setting 
    //[displayCurrentImage setImageWithURL:[NSURL URLWithString:dataItem.memoeryItemFullUrl]]; 
    //displayCurrentImage.contentMode = UIViewContentModeScaleAspectFit; 
    //[displayCurrentImage loadImageAtURL:[NSURL URLWithString:dataItem.memoeryItemFullUrl]]; 
    //end here 

    //for description view 
    //for date 
    dateLabel.text = @" September 2012"; 
    dateLabel.backgroundColor = [UIColor clearColor]; 
    dateLabel.font = [[Globals sharedInstance] getSingleViewFont]; 

    //for title 
    titleLabel.text = @" ROHGIT"; 
    titleLabel.backgroundColor = [UIColor clearColor]; 
    titleLabel.font = [[Globals sharedInstance] getSingleViewFont]; 

    //for description 
    descriptionText.text = @"ROHIT test description"; 
    descriptionText.delegate =self; 
    descriptionText.backgroundColor = [UIColor clearColor]; 
    descriptionText.font = [[Globals sharedInstance] getSingleViewFont]; 
    descriptionText.userInteractionEnabled = YES; 
    //for description 

    [DescriptionView addSubview:dateLabel]; 
    [DescriptionView addSubview:titleLabel]; 
    [DescriptionView addSubview:descriptionText]; 
    DescriptionView.hidden = YES; 
    //description view end here 
    displayCurrentImage.backgroundColor = [UIColor clearColor]; 
    //flipBtnImg.tag = currentImageIndex; 

    //for flip btn 
    [flipBtnImg setImage:[UIImage imageNamed:@"flip_img.png"] forState:UIControlStateNormal];        
    [flipBtnImg addTarget:self action:@selector(flipImageClickedMultiple:) forControlEvents:UIControlEventTouchUpInside]; 
    flipBtnImg.tag = (currentItem *100)+2; 
    flipBtnImg.backgroundColor = [UIColor clearColor]; 
    //flip btn end here 
    //for flip comment 
    [flipBtnCmt setImage:[UIImage imageNamed:@"flip_img.png"] forState:UIControlStateNormal];       
    [flipBtnCmt addTarget:self action:@selector(flipImageClickedMultipleComm:) forControlEvents:UIControlEventTouchUpInside]; 
    flipBtnCmt.tag = (currentItem*100)+6; 
    flipBtnCmt.backgroundColor = [UIColor clearColor ]; 
    //flip btn end here 
    DescriptionView.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:214/255.0 alpha:1]; 

    [DescriptionView.layer setBorderColor: [[UIColor whiteColor] CGColor]]; 
    [DescriptionView.layer setBorderWidth: 5.0]; 

    [newImageView addSubview:displayCurrentImage]; 
    displayCurrentImage.tag = (currentItem*100)+3; 
    [newImageView addSubview:DescriptionView]; 
    DescriptionView.tag = (currentItem*100)+4; 

    newImageView.backgroundColor = [UIColor clearColor]; 
    [displayCurrentImage.layer setBorderColor: [[UIColor whiteColor] CGColor]]; 
    [displayCurrentImage.layer setBorderWidth: 5.0];   
    [displayCurrentImage addSubview:flipBtnImg]; 
    [DescriptionView addSubview:flipBtnCmt]; 
    [mailScrollView addSubview:newImageView]; 
    xcoordinate = xcoordinate + totalWidth + reminaderWidth; 
    //currentImageIndex++; 
} 
mailScrollView.backgroundColor = [UIColor clearColor]; 
[self.view addSubview:mailScrollView]; 
} 
+0

请注明它是什么你正在尝试去做,而当你运行你的代码时会发生什么。看起来你在这里有两个或三个问题,但我不确定。 – bdesham

+0

我修改了我的问题,以便您可以清楚地知道我想问什么。 –

+0

嗨使用图像方向属性.... self.rawImage.image.imageOrientation – Spynet

回答

0

这种类型的,你需要打印/检测这样的....

switch (self.rawImage.image.imageOrientation) 
    { 
     case UIImageOrientationUp: 
      // would get you an exact copy of the original 
      NSLog(@"image orientation up"); 
      break; 


     case UIImageOrientationUpMirrored: 
      tran = CGAffineTransformMakeTranslation(rect.size.width, 0.0); 
      tran = CGAffineTransformScale(tran, -1.0, 1.0); 
      break; 

     case UIImageOrientationDown: 
      tran = CGAffineTransformMakeTranslation(rect.size.width, 
                rect.size.height); 
      tran = CGAffineTransformRotate(tran, M_PI); 
      break; 

     case UIImageOrientationDownMirrored: 
      tran = CGAffineTransformMakeTranslation(0.0, rect.size.height); 
      tran = CGAffineTransformScale(tran, 1.0, -1.0); 
      break; 

     case UIImageOrientationLeft: 
      bnds = swapWidthAndHeight(bnds); 
      tran = CGAffineTransformMakeTranslation(0.0, rect.size.width); 
      tran = CGAffineTransformRotate(tran, 3.0 * M_PI/2.0); 
      break; 

     case UIImageOrientationLeftMirrored: 
      bnds = swapWidthAndHeight(bnds); 
      tran = CGAffineTransformMakeTranslation(rect.size.height, 
                rect.size.width); 
      tran = CGAffineTransformScale(tran, -1.0, 1.0); 
      tran = CGAffineTransformRotate(tran, 3.0 * M_PI/2.0); 
      break; 

     case UIImageOrientationRight: 
      bnds = swapWidthAndHeight(bnds); 
      tran = CGAffineTransformMakeTranslation(rect.size.height, 0.0); 
      tran = CGAffineTransformRotate(tran, M_PI/2.0); 
      break; 

     case UIImageOrientationRightMirrored: 
      bnds = swapWidthAndHeight(bnds); 
      tran = CGAffineTransformMakeScale(-1.0, 1.0); 
      tran = CGAffineTransformRotate(tran, M_PI/2.0); 
      break; 

     default: 
      // orientation value supplied is invalid 
      assert(false); 
      return nil; 
    } 

我希望这将解决您的问题

+0

@Rohit嗨这是一个想法,你需要实现你的逻辑 – Spynet

+0

嗨图库视图请参考这篇文章http://stackoverflow.com/questions/3866766/how-to-create-a-gallery-on-ios – Spynet

相关问题