+ Preselecting an attachment works.

This commit is contained in:
moritz haarmann 2014-04-15 16:29:51 +02:00
parent d891af1929
commit 1df69d131a
3 changed files with 24 additions and 7 deletions

View File

@ -8,8 +8,12 @@
#import <UIKit/UIKit.h>
@class BITFeedbackMessageAttachment;
@interface BITAttachmentGalleryViewController : UIViewController
@property (nonatomic, strong) NSArray *messages;
@property (nonatomic, strong) BITFeedbackMessageAttachment *preselectedAttachment;
@end

View File

@ -54,8 +54,9 @@
[self setupScrollView];
self.view.frame = UIScreen.mainScreen.applicationFrame;
// self.view.frame.origin = CGPointZero;
self.tapognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[self.view addGestureRecognizer:self.tapognizer];
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
@ -64,6 +65,15 @@
[self.navigationController setNavigationBarHidden:YES animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
if (self.preselectedAttachment){
NSInteger indexOfSelectedAttachment = [self.extractedAttachments indexOfObject:self.preselectedAttachment];
if (indexOfSelectedAttachment != NSNotFound){
self.currentIndex = indexOfSelectedAttachment;
self.scrollView.contentOffset = CGPointMake(self.scrollView.frame.size.width * self.currentIndex, 0);
}
}
[self layoutViews];
@ -72,8 +82,7 @@
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.tapognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[self.view addGestureRecognizer:self.tapognizer];
}
- (void)setupScrollView {
@ -129,14 +138,16 @@
}
- (void)layoutViews {
CGPoint savedOffset = self.scrollView.contentOffset;
self.scrollView.delegate = nil;
self.scrollView.frame = self.view.bounds;
self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.bounds) * self.extractedAttachments.count, CGRectGetHeight(self.view.bounds));
self.scrollView.delegate = self;
self.scrollView.contentInset = UIEdgeInsetsZero;
self.scrollView.autoresizesSubviews = NO;
self.scrollView.contentOffset = savedOffset;
self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, 0);
NSInteger baseIndex = MAX(0,self.currentIndex-1);
NSInteger z = baseIndex;

View File

@ -773,14 +773,16 @@
- (void)listCell:(id)cell didSelectAttachment:(BITFeedbackMessageAttachment *)attachment {
BITAttachmentGalleryViewController *galleryController = [BITAttachmentGalleryViewController new];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:galleryController];
NSMutableArray *collectedMessages = [NSMutableArray new];
for (int i = 0; i<self.manager.numberOfMessages;i++){
[collectedMessages addObject:[self.manager messageAtIndex:i]];
}
[galleryController setMessages:collectedMessages];
[galleryController setMessages:collectedMessages];
[galleryController setPreselectedAttachment:attachment];
[self presentViewController:navController animated:YES completion:nil];
}