UIButtonni tegib harakatlantiring

Men foydalanmoqdaman:

[button addTarget:self action:@selector(moved:) forControlEvents:UIControlEventTouchDragInside];

Funktsiya kodi harakatlanishi:

- (IBAction)moved:(id)sender {
UIButton *t = sender;

UITouch *touch = [touch self];

CGPoint touchPoint = [touch locationInView: self];

t.center = touchPoint;
}

Shunday qilib, tugmachani sudrab boshlaganimda, to'satdan chap burchagida paydo bo'ladi (Coord: 0; 0). Men bu muammo deb o'yladim, chunki CGPoint touchPoint = [touch locationInView: self]; noto'g'ri ishlaydi. Menda 3 ta dars bor: viewController:

view = [[MainView alloc] initWithFrame:[self.view frame] ];
[self.view addSubview:view];

bu ko'rinish class mainview ob'ektidir (subclass uiview). Mainview i sinfda ob'ektni yaratadi (subclass uiview):

[self addSubview:but];

Keyin sinfda UIButtonni yaratib, UIControlEventTouchDragInside hodisasi bilan bog'lang (xabarning boshlanishini ko'ring).

Shunday qilib, kodimni qanday tuzatishim kerak, shu tugma tegish nuqtasiga to'g'ri yo'naltiriladi?

P.S. Afsuski, mening dahshatli inglizcha =)

1

1 javoblar

Agar siz haqiqatan ham UIControlEventTouchDragInside bilan bog'lanmoqchi bo'lsangiz, quyida parchadan foydalaning. Shaxsan men UIPanGestureRecognizer dan foydalanar edim. .

- (IBAction)moved:(UIButton *)sender {
    UITouch *touch = [touch self];
    CGPoint touchPoint = [touch locationInView: sender.superview];
    sender.center = touchPoint;
}
2
qo'shib qo'ydi
Muammoni qanday hal qildingiz?
qo'shib qo'ydi muallif Philipp Schmid, manba
Bartosz Ciechanovskiy - yaxshi fikr uchun rahmat! Lekin u xuddi shu muammoga o'xshaydi; Masalan, sensorli nuqtam (x; y), lekin u (x-100; y-100) deb tan olindi! Oldingi loyihalarda hammasi yaxshi edi, ammo hozir nima bo'lganini bilmayman.
qo'shib qo'ydi muallif Yaz, manba
Rahmat! Muammoni boshqa yo'l bilan hal qildim ...
qo'shib qo'ydi muallif Yaz, manba
Men to'g'ridan-to'g'ri UIPanGestureRecognizerga boraman :)
qo'shib qo'ydi muallif Bartosz Ciechanowski, manba