iOS 實現簡單的移動UIView代碼實例 – iPhone手機開發技術文章 iPhone軟體開發教學課程

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; 

發佈留言