0

私はアプリに取り組んでいます。ここでは、私が経験している奇妙な問題の単純化されたバージョンについて説明します。

ストーリーボードにも作成された UIImageView を使用して、ストーリーボードで作成されたビューコントローラーがあります。

次に、UIScrollView を UIImageview に追加し、スクロールビューにコンテナーを与えることを目的とした、次の h および m ファイルがあります。

h ファイル:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (strong, nonatomic) IBOutlet UIImageView *imageView;

@property (nonatomic, strong) UIScrollView* scrollView;
@property (nonatomic, strong) UIView* container;

@end

m ファイル:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImage *image = [UIImage imageNamed: @"new_phots_fake_port.png"];
    //Add the image to the imageView I created in the Storyboard
    [_imageView setImage:image];


    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(60.0, 70.0, 522.0, 100.0)];
    [_scrollView setBackgroundColor:[UIColor yellowColor]];


    // Set up the container view to exist inside the scrollview:
    CGSize containerSize = CGSizeMake(5000.0f, 730.0f);
    _container = [[UIView alloc] initWithFrame:(CGRect){.origin=CGPointMake(0.0f, 0.0f),       .size=containerSize}];
    _container.backgroundColor = [UIColor redColor];
    // Tell the scroll view the size of the contents
    self.scrollView.contentSize = containerSize;
    [_scrollView addSubview:_container];


    [_imageView addSubview:_scrollView]; //This is what I want but doesn't allow scrolling

    //[self.view addSubview:_scrollView];  //This allows scrolling but makes the imageView      and Scrollview siblings.  I need scrollview to be a child of imageview
   }

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

そのため、スクロールビューをイメージビューに追加できないようです (そして正しく機能します)。 なぜですか?私は何を間違っていますか?

奇妙なことに、デリゲート メソッドの viewForZoomingInScrollView または scrollViewDidZoom も使用しませんでした。なぜこれらが必要でなかったのかわかりません。

4

1 に答える 1

1

で userInteractionEnabled を設定する必要がありますUIImageView

_imageView.userInteractionEnabled = YES;
于 2012-10-05T23:06:40.840 に答える