UIScrollview 中的触摸事件

发布于 2024-10-20 13:27:33 字数 1674 浏览 5 评论 0原文

我是 iPhone 开发新手。我有很多 UIImageView 在运行时作为子视图添加到 self.view 中。

我当前的架构是:

  1. UIView内部有一个UIScrollView,在UIScrollView内部有另一个UIView附加到名为 SeatingPlanUIView 子类。
  2. SeatingPlan 仅在屏幕上绘制网格。
  3. UIImageView 由名为 SeatingPlanViewContollerUIViewController 子类绘制在屏幕上。 UIImageView 作为子视图添加。

UIImageView 保存在 NSMutableArray 中。

.h 文件:

@interface SeatingPlanViewController : UIViewController <UIScrollViewDelegate, UIAlertViewDelegate>{
    IBOutlet UIScrollView * scrollView;
    SeatingPlan * planView;
    CGPoint  origin;
    NSMutableArray * arrayOfImages;
}

.m 文件:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.navigationItem setTitle:@"Seating Planner"];

    UIBarButtonItem *mySave = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(Save)];
    self.navigationItem.rightBarButtonItem = mySave;
    [mySave release];

    segmentController.selectedSegmentIndex = UISegmentedControlNoSegment;
    segmentController.momentary = YES; 

    scrollView.contentSize=CGSizeMake(1280.0,960.0);

    [scrollView setBackgroundColor:[UIColor whiteColor]];
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;    
    [planView addSubview:scrollView];
    [self.view addSubview:planView];
}

我想在屏幕上移动 UIImageView 。我更喜欢一些示例代码。

我应该将触摸处理代码放在哪里?在视图控制器子类中还是在 UIView 子类中?

I'm new to iPhone development. I have so many UIImageViews added as subview at runtime to the self.view.

My current architecture is:

  1. Inside UIView there is a UIScrollView and inside UIScrollView there is another UIView which is attached to a UIView sub class named SeatingPlan.
  2. SeatingPlan only draws the grid on the screen.
  3. The UIImageViews are drawn on the screen the by UIViewController sub class named SeatingPlanViewContoller. The UIImageViews are added as the subviews.

The UIImageViews are saved in an NSMutableArray.

The .h file:

@interface SeatingPlanViewController : UIViewController <UIScrollViewDelegate, UIAlertViewDelegate>{
    IBOutlet UIScrollView * scrollView;
    SeatingPlan * planView;
    CGPoint  origin;
    NSMutableArray * arrayOfImages;
}

The .m file:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.navigationItem setTitle:@"Seating Planner"];

    UIBarButtonItem *mySave = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(Save)];
    self.navigationItem.rightBarButtonItem = mySave;
    [mySave release];

    segmentController.selectedSegmentIndex = UISegmentedControlNoSegment;
    segmentController.momentary = YES; 

    scrollView.contentSize=CGSizeMake(1280.0,960.0);

    [scrollView setBackgroundColor:[UIColor whiteColor]];
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;    
    [planView addSubview:scrollView];
    [self.view addSubview:planView];
}

I want to move the UIImageViews on the screen. I would prefer some sample code.

Where should I put my touch handling code? In the view controller subclass or in the UIView subclass?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文