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

相關問題