1

Situation

I got two views:

  • A superview (which contains:)
  • A subview (which has a customised DrawRect function

Draw function

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 3.0);
CGContextSetFillColorWithColor(context, self.targetColor.CGColor);
CGContextAddRect(context, CGRectStandardize(self.target));
CGContextFillPath(context);

So this DrawRect function just draws a rectangle in the subviews coordinate System at a certain position (Which is likely to be offscreen, when dislayed in the subview)

In my View Controller I've got Outlets to both of them. The View Controller will regulary call a function on an object which contains my data model. This object will return a CGRect, that defines the area i want to display. (In the subviews coordinate system)

Intended Behavior

So i don't care how its done, as long as it is efficient enough to be called at 20 Hz. But i want exactly, that only that area is drawn and scaled to fit in the superview. So its translation and scale (Things I'm certainly not an expert in). And this process will be repeated over and over again.

What I've tried so far

I managed to get this working with a CGImageRef etc.(So the data model works as intended) but not with a custom view. Changing the superviews bounds will do the translation but I've not managed to get scaling working. I hope there is a way to solve this by changing some Views bounds or frame and define some automatic resize behaviour, but i couldn't manage to find out how. Another thing could be to define a function that builds an CGAffineTransformMatrix which then will be applied to the subview. But as i said this stuff is new to me and figured that it will take someone with experience only a couple of minutes to point me into the right direction.

So a perfect opportunity for you guys to show off some skills ;)

4

0 回答 0