Reputation: 500
Within a collection view cell I have a textview which is created in
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
I'm creating a bezier path for text exclusion as below
CGRect exclusionRect=CGRectMake(0,0, cell.coverImage.frame.size.width, cell.coverImage.frame.size.height);
UIBezierPath *exclusionPath=[UIBezierPath bezierPathWithRect:exclusionRect];
cell.issueInfo.textContainer.exclusionPaths=@[exclusionPath];
However, when the textview scrolls the bezier path stays fixed within the textview and therefore my text becomes masked by the image.
How do get the bezier path to not move when the text view scrolls?
Upvotes: 1
Views: 516
Reputation: 500
I resolved this by having my custom UICollectionViewCell subclass adopt the UITextViewDelegate protocol and setting the cell as the delegate in
-(void)awakeFromNib
As the UITextViewDelegate protocol inherits from the UIScrollView protocol I implemented
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
Inside this method I calculate and apply the bezierpath as below
self.exclusionPath=[UIBezierPath bezierPathWithRect:[self.textView convertRect:self.imageView.bounds fromView:self.imageView]];
self.textView.textContainer.exclusionPaths=@[self.exclusionPath];
Hope this helps someone!
Upvotes: 3