私はスクリーンショットを表示するためにAppStoreアプリケーションとまったく同じエフェクトを作成しようとしています.UITableView内には、UITableViewCellのカスタムサブクラスがあります。そのうちの1つは、いくつかの製品、例えば4つの画像のプレビューを表示するように設計されています。 AppStoreがアプリのスクリーンショットを表示するのと同じ方法で表示するようにします。水平なUIScrollViewの内部に、UIPageControlが添付されています。UITableViewCell内の水平UIScrollView
だから私はちょうどそのように、私のUITableViewCellに私UIScrollViewの、私のUIPageControlを追加します。
@implementation phVolumePreviewCell
- (id)init {
if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kVolumePreviewCellIdentifier]) {
[self setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
[self setSelectionStyle:UITableViewCellSeparatorStyleNone];
previews = [[NSMutableArray alloc] initWithCapacity:4];
for (int i = 0; i < 4; i++) {
[previews addObject:@"dummy"];
}
scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
[scrollView setPagingEnabled:YES];
[scrollView setBackgroundColor:[UIColor grayColor]];
[scrollView setIndicatorStyle:UIScrollViewIndicatorStyleBlack];
[scrollView setShowsHorizontalScrollIndicator:YES];
[scrollView setBounces:YES];
[scrollView setScrollEnabled:YES];
[scrollView setDelegate:self];
[self.contentView addSubview:scrollView];
[scrollView release];
pageControl = [[UIPageControl alloc] initWithFrame:CGRectZero];
[pageControl setNumberOfPages:[previews count]];
[pageControl setBackgroundColor:[UIColor grayColor]];
[self.contentView addSubview:pageControl];
[pageControl release];
}
return self;
}
は(注:私はちょうど[プレビューを持つために、ここではダミーデータで「プレビュー」を投入していますcount]は動作しています;私はscrollViewのスクロールインジケータをテスト目的でのみ表示したいので、後で非表示にします)。
私の問題は、このphVolumePreviewCell(UITableViewCellのサブクラス)を含むUITableView全体をスクロールすることができますが、私はUIScrollViewをスクロールできません。どうすればこれを達成できますか?
私が見つけた唯一の情報は次のとおりです:http://theexciter.com/articles/touches-and-uiscrollview-inside-a-uitableview.html 古いSDK(すなわち2.2)について話していますが、これを行うための「最近の」アプローチがあると確信しています。
いくつかの精度:
- 私は2本の指でUIScrollViewのをスクロールすることができます。それは私が欲しいものではない、私はそれが1本の指でのみスクロールできるようにしたい。
- 2本の指でスクロールすると、TableViewはまだタッチを傍受し、少し上または下にスクロールします。 ScrollViewに触れるとTableViewをその位置に固定したいと思います。
は、私は私のtableViewにタッチを傍受する方法を動作するように持っていると信じて、そしてタッチがphVolumePreviewCell(カスタムUITableViewCellのサブクラス)にある場合、テーブルビューでそれを処理するのではなく、セルにそれを渡します。レコードの
は、私のテーブルビューはのUITableViewControllerのサブクラスでプログラム作成されます。任意の助け
@interface phVolumeController : UITableViewController <UITableViewDelegate> {
LocalLibrary *lib;
NSString *volumeID;
LLVolume *volume;
}
- (id)initWithLibrary:(LocalLibrary *)newLib andVolumeID:(NSString *)newVolumeID;
@end
@implementation phVolumeController
#pragma mark -
#pragma mark Initialization
- (id)initWithLibrary:(LocalLibrary *)newLib andVolumeID:(NSString *)newVolumeID {
if (self = [super initWithStyle:UITableViewStylePlain]) {
lib = [newLib retain];
volumeID = newVolumeID;
volume = [(LLVolume *)[LLVolume alloc] initFromLibrary:lib forID:volumeID];
[[self navigationItem] setTitle:[volume title]];
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kVolumePreviewCellIdentifier];
if (cell == nil) {
cell = [[[phVolumePreviewCell alloc] init] autorelease];
}
[(phVolumePreviewCell *)cell setVolume:volume];
return (UITableViewCell *)cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return kVolumePreviewCellHeight;
}
感謝を!
Thanks Cyrille !!同じ問題がここにあります。あなたの解決策は私に絶望の時間の多くを救った! :-) –
こんにちはCyrille - これは古いSOの質問ですが、このソリューションのサンプルアプリを持っているのだろうかと思いました。ありがとう.. – Craig
@Craig:いいえサンプルアプリ、申し訳ありません。このコードはそれ以来進化しており、私はもうこれを使用しません。しかし、本当に、この状況を再現するために必要なコードはすべて私の記事にあります。 – Cyrille