0

我是目标 c 的新手。

我有两个问题。

我想做的是显示像 iphone galary 这样的图像。我正在使用滚动视频。我尝试在许多帖子中使用 fgalary 和其他提到的 galary,但它们不符合我的要求,因为我必须在其中进行许多自定义。

//修改评论

我想要做的是以单独的帧大小显示以移植模式拍摄的图像,如 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 回答