开发者

Forward events from UIScrollView to UIButton

开发者 https://www.devze.com 2023-03-06 12:13 出处:网络
I got an UIButton inside an UIScrollView. The problem is that the UIButton is not big enough to fill the entire UIScrollView. I\'d like to be able to forward开发者_JS百科 the touch events in other are

I got an UIButton inside an UIScrollView. The problem is that the UIButton is not big enough to fill the entire UIScrollView. I'd like to be able to forward开发者_JS百科 the touch events in other areas of the UIScrollView to the UIButton. Here's a screenshot of my app:

http://imageshack.us/photo/my-images/405/img1410.png/

Does anyone knows how to do that?


[button addTarget:self action:@selector(itemTouched:)forControlEvents:UIControlEventTouchUpInside];

- (void) itemTouched:(UIButton*) sender
{
  [self performSelectorOnMainThread:@selector(doSomething:) withObject:sender waitUntilDone:NO];
}

The highlight of UIButton can be shown before call doSomething method.


I'm not sure you can forward touches in that manner, but I guess you could resize the UIButton to fill the whole scrollView and make the content not stretch, such that it looks identical, but there'd be a much bigger UIButton.


To propagate touches down the chain to a sub view use:

[mychild touchesBegan:touches withEvent:event];

in your scrollView's touchesBegan.

0

精彩评论

暂无评论...
验证码 换一张
取 消