I want to draw an rectangle and can change the rectangle’s position and size realtime.
I have tried following two methods, but the view don’t show the rectangle.
do you have any advice or example?
appreciate your help.
use view frame (it only show the new rectangle when restart the app)
UIView * drawView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 10, 10)];
[self.view addSubview:drawView];
drawView.layer.borderColor = [[UIColor orangeColor] CGColor];
drawView.layer.borderWidth = 2;
drawView.frame = CGRectMake(r.x, r.y, r.width, r.height);
draw in the drawRect
fav = [[FaceAugmentingView alloc] initWithFrame:[imageView frame]];
fav.backgroundColor = [UIColor clearColor];
[self.view addSubview: fav ];
fav.face = CGRectMake(r.x, r.y, r.width, r.height);
[fav setNeedsDisplay];
I suggest you add a method that reloads the faces based whenever you need to alter it. Declare and array that will help us keep track of all the views we’ve added.
And then implement
reloadFacessomething like this –I would expect
reloadFacesto be called when there is a change of some kind.numberOfFacesInImageandframeForFaceAtIndex:are methods that you will have to implement based on how you get the data. You can also replace them to suit your data model. Don’t forget to initializefaceViews.