【发布时间】:2012-12-18 09:05:33
【问题描述】:
这是我的代码:
#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”。
提前致谢!
【问题讨论】:
-
将
rect1保存为实例变量。 -
这与您的问题无关,但它在 Objective C 中的标准是以大写字母开头的类名(即 TempViewController 和 MyRect)。这使得区分对象和类变得更加容易。
-
好的,谢谢!会做。现在谁给了我的问题一个负1....大声笑
标签: objective-c class methods instance