iOS 实现简单的移动UIView代码实例
来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:33 点击:次
iOS 实现简单的移动UIView代码实例
在iewDidLoadzh中创建UIView
[cpp]
UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(30.0, 30.0, 45.0, 45.0)];
tmpView.backgroundColor = [UIColor brownColor];
tmpView.tag = 100;
[self.view addSubview:tmpView];
[tmpView release];
实现简单的移动UIView
[cpp]
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
UIView *viewDemo = (UIView*)[self.view viewWithTag:100];
CGPoint point = [touch locationInView:self.view];
CGRect frame = viewDemo.frame;
frame.origin = point;
viewDemo.frame = frame;
}
在iewDidLoadzh中创建UIView
[cpp]
UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(30.0, 30.0, 45.0, 45.0)];
tmpView.backgroundColor = [UIColor brownColor];
tmpView.tag = 100;
[self.view addSubview:tmpView];
[tmpView release];
实现简单的移动UIView
[cpp]
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
UIView *viewDemo = (UIView*)[self.view viewWithTag:100];
CGPoint point = [touch locationInView:self.view];
CGRect frame = viewDemo.frame;
frame.origin = point;
viewDemo.frame = frame;
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>