我有一个实现水平图库的应用。在我的故事板中,当一个作业(桌面视图中的单元格)被点击时,它将重定向并显示作业详细信息。在我的工作细节场景中:我有索引0:公司徽标和名称,工资和职位。在索引1中:我有水平图库 - 我以编程方式创建了一个scrollview,并在scrollview中创建了一个图像视图。 这是我创建滚动视图和图像视图的方式:
else if (indexPath.section == 1)
{
[self getImages];
[cell.contentView addSubview:self.scrollView];
return cell;
}
- (void)getImages
{
mutableURLstorage = [[NSMutableArray alloc] init];
imagesArray = [[NSMutableArray alloc]init];
NSInteger noOfImages = (unsigned long)[mutableStorage count];
NSString* strURL;
//store image_paths (company and branch) in a mutable array
for (int i = 0; i < noOfImages; i++)
{
NSDateFormatter *df=[[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *date = [NSDate date];
NSDate *oneMinLater = [date dateByAddingTimeInterval:1444];
NSString *hmac_body =[NSString stringWithFormat:@"%@\n%lld\n%@",METHOD,[@(floor([oneMinLater timeIntervalSince1970])) longLongValue],CONTAINER_PATH] ;
// below get different string with shaA diagest
const char *cKey2 = [KEY cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData2 = [hmac_body cStringUsingEncoding:NSASCIIStringEncoding];
unsigned char cHMAC2[CC_SHA1_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA1, cKey2, strlen(cKey2), cData2, strlen(cData2), cHMAC2);
NSData *HMAC2 = [[NSData alloc] initWithBytes:cHMAC2 length:sizeof(cHMAC2)];
NSString *HMACStr = [[HMAC2 description] stringByReplacingOccurrencesOfString:@"<" withString:@""];
HMACStr = [HMACStr stringByReplacingOccurrencesOfString:@">" withString:@""];
HMACStr = [HMACStr stringByReplacingOccurrencesOfString:@" " withString:@""];
strURL = [NSString stringWithFormat:@"%@%@?temp_url_sig=%@&temp_url_expires=%lld", URLstorage, CONTAINER_PATH, HMACStr, [@(floor([oneMinLater timeIntervalSince1970])) longLongValue]];
[mutableURLstorage addObject:strURL];
[imagesArray addObject:[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]]]];
}
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGSize pageSize = CGSizeMake(ITEM_WIDTH, self.scrollView.frame.size.height);
_pgCtr = [[UIPageControl alloc] initWithFrame:CGRectMake(0, screenRect.size.height-30, 320, 36)];
_pgCtr.backgroundColor=[UIColor grayColor];
int numberofPage=ceil((float)[imagesArray count]/3.5);
_pgCtr.numberOfPages= numberofPage;
self.scrollView.contentSize = CGSizeMake(320*numberofPage, pageSize.height);
int imgCurrentX = 10;
for (UIImageView* image in imagesArray) {
@autoreleasepool {
imageview = [[UIImageView alloc] initWithFrame:CGRectMake(imgCurrentX, 0, 70, 70)];
imageview.image = (UIImage*)image;
[imageview setUserInteractionEnabled:YES];
[self.scrollView addSubview:imageview];
imgCurrentX = imgCurrentX+80;
}
}
}
我能够显示水平图库,但图像全部用于缩略图。 现在我在viewDidLoad中实现了这个代码,以确定是否点击了imageview:
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction:)]];
在我的 singleTapAction 方法中,我使用LeveyPopListView来显示放大的图像。
- (void)singleTapAction:(UIGestureRecognizer *)singleTap_
{
[self createLeveyPopList];
}
- (void)createLeveyPopList
{
NSString *jobs_name = @"JOBSD";
if(self.lplv.delegate != nil)
return;
self.lplv = [[LeveyPopListView alloc] initWithTitle:@"The following jobs are located here:" options:imagesArray jobName:jobs_name handler:^(NSInteger anIndex) {
}];
self.lplv.delegate = self;
[self.lplv showInView:self.view animated:YES];
}
我在弹出窗口中所做的是重新显示原始图像库(作业详细信息场景中的图像库),但图像被放大了。我的应用程序成功实现了水平图库。现在我的问题是,例如图像2被点击,我需要首先显示图像2而不是首先显示图像1。 我希望有人可以帮助我。谢谢!
答案 0 :(得分:0)
添加一种方法来更改包含图像的ImageView的大小,如下所示:
- (IBAction)buttonTapped:(id)sender {
// Use this Sender property to your advantage
[yourImageViewName setFrame:CGRectMake(0, 0, 100, 100)];
}
当然,根据您的需要调整坐标。您还可以在IB中的图像视图设置中进行游戏,以确保在放大时图片不会变形。
现在,您还可以为图片添加标签,并根据您按下的标签放大图片视图。如果您想转而使用该路线,请告诉我,我会发布该代码。我希望我能帮忙!