サムネイル画像を下に並べてスクロールさせたいです。そして表示したいサムネイル画像をタップするとメインの表示したい画像に移動させたいです。
しかしサムネイル画像が表示されないのと、オブジェクトの位置とサイズの書き方がうまくいきません。
サムネイル画像のサイズはw100h75です。
下記のコードまで書いてみました。どうかご教授お願い致します。
サムネイル部分のコードは現在このように書いております。
【MWPhotoBrowser.m】
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//サムネイル部分
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:self.view.bounds];
ThumbnailView *uv = [[ThumbnailView alloc] initWithFrame:CGRectMake(0, 0, 100*8, 75)];
[sv addSubview:uv];
sv.contentSize = CGSizeMake(47, 71);
sv.center = CGPointMake(0, 605);
[self.view addSubview:sv];
// Checks
if (!_viewIsActive || _performingLayout || _rotating) return;
// Tile pages
[self tilePages];
// Calculate current page
CGRect visibleBounds = _pagingScrollView.bounds;
int index = (int)(floorf(CGRectGetMidX(visibleBounds) / CGRectGetWidth(visibleBounds)));
if (index < 0) index = 0;
if (index > [self numberOfPhotos] - 1) index = [self numberOfPhotos] - 1;
NSUInteger previousCurrentPage = _currentPageIndex;
_currentPageIndex = index;
if (_currentPageIndex != previousCurrentPage) {
[self didStartViewingPageAtIndex:index];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//サムネイル
NSMutableArray* imageList = [NSMutableArray array];
for (int i=0; i < 8; i++) {
UIImage* image = [UIImage imageNamed:
[NSString stringWithFormat:@"image%02ds.jpg", i+1]];
[imageList addObject:image];
}
self.thumnailView.imageList = imageList;
CGRect rect = CGRectMake(0, 0, 100*8, 75);
self.thumnailView.frame = rect;
self.scrollView.contentSize = rect.size;
[self touchedAtIndex:0];
#import
@class MWPhotoBrowser;
@interface ThumbnailView : UIView {
MWPhotoBrowser* viewController_;
NSMutableArray* imageList_;
NSInteger selectedIndex_;
}
@property (nonatomic, assign) IBOutlet MWPhotoBrowser* viewController;
@property (nonatomic, retain) NSMutableArray* imageList;
@end
#import ”ThumbnailView.h”
#import ”MWPhotoBrowser.h”
@implementation ThumbnailView
@synthesize viewController;
@synthesize imageList;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGPoint p = CGPointZero;
for (UIImage* image in self.imageList) {
[image drawAtPoint:p];
p.x += image.size.width;
}
[[UIColor greenColor] set];
CGRect frame = CGRectMake(selectedIndex_*100, 0, 100, 75);
UIRectFrame(frame);
}
- (void)dealloc
{
[super dealloc];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
selectedIndex_ = location.x / 100;
[self setNeedsDisplay];
[self.viewController touchedAtIndex:selectedIndex_];
}
@end