【问题标题】:How to add two uiscrollviews as subview如何添加两个uiscrollviews作为子视图
【发布时间】:2011-09-12 16:39:13
【问题描述】:

经过几天的大量研究和工作,我真的需要一些指导。我正在尝试将 uiscrollview 添加到彼此之上。我有两个 UIScrollView:ImageScrollView 和 MarkScrollView。我想将 MarkScrollView 作为子视图添加到 ImageScrollView。 ImageScrollView 添加到 UIViewController MapImageViewController。 在 ImageScrollView 中,它由 tiledLayer 中的图像组成。在 MarkScrollView 中,它由具有指针图像的 imageview 组成。但由于某种原因,它不能作为子视图添加到其他视图。我已经添加了我的代码。如果有人可以帮助我找出错误,将不胜感激。

/** ImageScrollView.m 它在ImageScrollView之上添加了uiview***/

UIView *imageView = [[TileView alloc] initWithImageName:imageName size:imageSize];
[(TileView *)imageView setAnnotates:NO]; // ** remove this line to remove the white tile grid **
[self addSubview:imageView];

/** MarkScrollView.m 它在 MarkScrollView 之上添加带有 uiimages 的 uiview**/

UIImage *markerimage = [UIImage imageNamed:@"map.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: markerimage];
imageView.image = markerimage;
[imageView setFrame:CGRectMake(100,100,50,50)];
imageview = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];
[imageview setBackgroundColor:[UIColor blackColor]];
[imageview addSubview: imageView];
[self addSubview:imageview];

/** MapImageViewController.m 它在另一个 UIScrollView pagingScrollView 之上添加 ImageScrollView **/

 UIScrollView *pagingScrollView;
 ImageScrollView *page = [[[ImageScrollView alloc] init] autorelease];
 [pagingScrollView addSubview:page];

  MarkScrollView *markerScroll = [[[MarkScrollView alloc] init] autorelease];
  [page addSubview:markerScroll]; /**But it never adds the other scrollview here **/

/** MapImageViewController.h **/

@interface MapImageViewController : UIViewController <UIScrollViewDelegate, UIGestureRecognizerDelegate> {

ImageScrollingView *imageScrollView;
MarkerIconsScrollView *markerScrollView;
}

【问题讨论】:

    标签: iphone objective-c uiview uiscrollview uiimageview


    【解决方案1】:
    UIScrollView *pagingScrollView;
     ImageScrollView *page = [[[ImageScrollView alloc] init] autorelease];
     [pagingScrollView addSubview:page];
    
      MarkScrollView *markerScroll = [[[MarkScrollView alloc] init] autorelease];
      [page addSubview:markerScroll]; /**But it never adds the other scrollview here **/
    

    我注意到这段代码 sn-p 的一些内容:

    1. pagingScrollView 从未初始化
    2. 您添加到其中的视图(假设它实际上是用一个有效的框架初始化的),不是用一个框架来初始化的。总是使用 - (id)initWithFrame:(CGRect)aRect 来初始化你的 UIViews

    祝你好运!

    【讨论】:

    • 我已经用 initWithFrame 和 pagingScrollView 初始化了每个 UIView。我没有在此处包含该代码,因为它太大了。但是我做对了吗?
    • 不。实际上,在 UIScrollView 上添加此类图像需要某种注释。
    猜你喜欢
    • 2013-08-08
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多