Question

I am new in objective c.

I have two probelms.

What I wanted to do is to display the images like iphone galary. I am using the scroll video for the same. I tried using fgalary and other mention galary in many posts but they are not as per my requirement as I will have to do many customization in that.

//modified comment

what I wanted to do is show images taken in portrate mode in separate frame size like CGRectMake(0, 0, 243, 314) and if image is taken in landscape mode then show it in seperate frame like CGRectMake(0, 0, 300, 200)..All the images are uplaoded on server, as previously I shown all the images in same frame so Images look stretch while displaying so I am doing it like this way.

I even tried getting the height and width of image loading from server like shown in below code but that even not working for the images loading from server. Please suggest me some better way to resolve my issue.

my code

-(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];
}
Was it helpful?

Solution

This type you need to print / detect like this....

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;
    }

i hope this will solve your issue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top