1
votes

I am trying to display a 3rd party UIView, which basically contains an image with some clickable (touchable) regions. For example, it contains a region, that when clicked, launches a web page. I created a UIViewController for this which is supposed to show this UIView as a full screen. I know the width and height of the image, so I need to scale this view to fit the full screen.

Here is my problem: When I try to scale the image, the clickable regions in the subview are no longer clickable.

Here is how I am doing the scaling:

    float scalingFactor = (adAspectRatio > deviceAspectRatio) ? deviceWidth / adWidth : deviceHeight / adHeight;
    float scaledWidth = adWidth * scalingFactor;
    float scaledHeight = adHeight * scalingFactor;
    adFrame = CGRectMake((deviceWidth - scaledWidth) / 2.0f, (deviceHeight - scaledHeight) / 2.0f, adWidth, adHeight);
    thirdpartyview.transform = CGAffineTransformScale(CGAffineTransformIdentity, scalingFactor, scalingFactor);
    [thirdpartyview setFrame:adFrame];
    ...
    [self.view addSubview:thirtpartyview];

On doing the transform, all the touches now go to my view controller, instead of that subview. Now I can't click anything. If I do not do the transform, or if I do the transform but using identity, everything works, but it is not scaled as I want it to. When I transform, it scales correctly, but the touches don't work.

If I try to detect touches on the view controller, I am able to receive touch events. But I don't know how to forward the touch events to the thirdparty view.

Any suggestions?

1

1 Answers

0
votes

I figured out my issue. I was doing the transform too early. Basically, the transform was being done before the subviews even existed in the third party view. Once I figured out the right time to perform the transform, I was able to scale the view fulls screen by doing the following in my view controller:

CGRect screen = [[UIScreen mainScreen] bounds];
float deviceWidth = screen.size.height;
float deviceHeight = screen.size.width;
if (_mask & UIInterfaceOrientationMaskPortrait) {
    deviceWidth = screen.size.width;
    deviceHeight = screen.size.height;
}

CGRect r = self.yadView.frame;
float scaledWidth = r.size.width*_scalingFactor;
float scaledHeight = r.size.height*_scalingFactor;
self.yadView.center = CGPointMake(scaledWidth/2.0f, scaledHeight/2.0f);
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, (deviceWidth - scaledWidth) / 2.0f, (deviceHeight - scaledHeight) / 2.0f);
transform = CGAffineTransformScale(transform, _scalingFactor, _scalingFactor);
self.thirdpartyview.transform = transform;