UIScrollview 中的触摸事件
我是 iPhone 开发新手。我有很多 UIImageView
在运行时作为子视图添加到 self.view
中。
我当前的架构是:
- 在
UIView
内部有一个UIScrollView
,在UIScrollView
内部有另一个UIView
附加到名为SeatingPlan
的UIView
子类。 SeatingPlan
仅在屏幕上绘制网格。UIImageView
由名为SeatingPlanViewContoller
的UIViewController
子类绘制在屏幕上。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 UIImageView
s added as subview at runtime to the self.view
.
My current architecture is:
- Inside
UIView
there is aUIScrollView
and insideUIScrollView
there is anotherUIView
which is attached to aUIView
sub class namedSeatingPlan
. SeatingPlan
only draws the grid on the screen.- The
UIImageView
s are drawn on the screen the byUIViewController
sub class namedSeatingPlanViewContoller
. TheUIImageView
s are added as the subviews.
The UIImageView
s 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 UIImageView
s 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论