这是我的代码:
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(50.0, 50.0, 0, 0)];
[self.view addSubview:view1];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if([touch.view isEqual:self]) {
CGPoint point = [[touches anyObject] locationInView:self];
NSLog(@"%@",NSStringFromCGPoint(point));
self.view1.center = point;
}
}
我希望能够从 touchesMoved 方法访问“UIView”类的实例“view1”。
提前致谢!