0

私はObjectiveCで新しいです。

私は2つのprobelmsを持っています。

私がやりたかったのは、iphoneギャラリーのような画像を表示することです。私は同じためにスクロールビデオを使用しています。私は多くの投稿で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];
}
4

1 に答える 1

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

これで問題が解決することを願っています

于 2012-09-12T09:25:35.643 に答える