如果我在我的应用程序中显示多个这样的图像
UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
imageScrollView.pagingEnabled = YES;
NSInteger numberOfPhotos = 61;
for (int i = 0; i < numberOfPhotos; i++) {
CGFloat xOrigin = i * self.view.frame.size.width;
NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
_imageView.tag = 122;
imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);
编辑:
imageView.image = [UIImage imageNamed:imageName];
将上述语句添加到代码后仍然无法正常工作。
UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
imageScrollView.userInteractionEnabled = YES;
[imageScrollView addGestureRecognizer:gestureRecognizer];
gestureRecognizer.delegate = self;
imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfPhotos, self.view.frame.size.height);
现在在滚动视图中显示图像后,如果长按滚动视图中的任何图像,将显示带有保存照片按钮的操作表
- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Save Photo", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[actionSheet showInView:self.view];
[actionSheet release];
}}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
[self savePhoto];
break;
default:
break;
}}
按下保存照片按钮时
-(void)savePhoto{
UIImageWriteToSavedPhotosAlbum(_imageView.image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);
}
但是在执行应用程序时,它不会将任何照片保存到相册。我是否错过了一些重要的信息来放入代码以使其工作。
感谢帮助。