好岸园IT技术学习网 hopean.com IT新闻 js网页特效 it技术 二次开发

iOS 实现简单的移动UIView代码实例

iOS 实现简单的移动UIView代码实例

在iewDidLoadzh中创建UIView

请访问http://www.hopean.com

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
-(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;
}


posted @ 2012-11-27 10:54  hopeanCom  阅读(323)  评论(0编辑  收藏  举报