0

I have several rounded rect's that i filled and set a blend mode to make it blend to the background image by doing something like this:

UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
UIImage *bgImage = [UIImage imageNamed:@"UEmenubackground.png"];
[bgImage drawInRect:self.view.frame];

UIBezierPath *textField1 = [UIBezierPath bezierPathWithRoundedRect:textField1Rect cornerRadius:21];
[[UIColor colorWithRed:174.0f/255.0f green:9.0/255.0f blue:34.0f/255.0f alpha:1.0] setFill];
[textField1Path fillWithBlendMode:kCGBlendModeOverlay alpha:1.0f];

UIBezierPath *textField2Path = [UIBezierPath bezierPathWithRoundedRect:textField2Rect cornerRadius:21];
[[UIColor colorWithRed:0 green:0 blue:0 alpha:.35] setFill];
[textField2Path fillWithBlendMode:kCGBlendModeNormal alpha:1.0f];

UIImage *drawnImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageView *finishedBGImage = [[UIImageView alloc] initWithImage:drawnImage];
[self.view addSubview:finishedBGImage];
[self.view sendSubviewToBack:finishedBGImage];

On top of these rounded rects I have text fields which the user can enter text. To make the screen less crammed I want to try to put the text fields on a scroll view with the background staying stationary however I am having trouble finding a way to redraw the rounded rects to blend with the background as it scrolls. I tried redrawing them each time the UIScrollView:DidScroll: delegate method was called but it was incredibly slow and clunky. From what I have read it looks like it is not possible but I figured I would ask around and see if anyone has a solution. Thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
coal175
  • 273
  • 1
  • 3
  • 10
  • I'm not sure I follow: do you want the rounded rect to scroll or not? Does it matter that they are filled with a blend mode? – SwiftArchitect Feb 07 '16 at 21:09
  • The background has a gradient so the color of the rounded rect changes depending on where it is with respect to the stationary background. What i tried to do was redraw the background image each time the scroll view "didScroll" so the rounded rect could be colored appropriately depending on where it was now placed on the background. – coal175 Feb 08 '16 at 15:07
  • Look at this answer: it demonstrates `scrollViewDidScroll`, and is everything but slow or clunky. http://stackoverflow.com/a/33723894/218152 – SwiftArchitect Feb 08 '16 at 15:14
  • I understand how scrollViewDidScroll works. It gets slow and clunky however when you try to redraw the background each time within that method so that the rounded rect can move and be draw according to where on the background using the blend mode i set in the fill. – coal175 Feb 09 '16 at 03:01
  • Is this the complete code above? Can you add a little bit of context so that it can be built and tested? – SwiftArchitect Feb 09 '16 at 04:00

0 Answers0