CGRect
textViewRect =
CGRectInset(self.view.bounds,
10.0,
20.0);
_myTextView
= [[UITextView
alloc]
initWithFrame:textViewRect];
_myTextView.text
= text;
_myTextView.editable
=
NO;
_myTextView.delegate
=
self;
[self.view
insertSubview:_myTextView
belowSubview:_imageView];
//使用TextView的_textView.textContainer.exclusionPath属性指定环绕路径
_myTextView.textContainer.exclusionPaths
=
@[[self
translatedBezierPath]];
//为了让图片跟随textView一起滚动,必须在滚动监听里动态改变imageView的y
-(void)scrollViewDidScroll:(UIScrollView
*)scrollView{
_imageView.frame
=
CGRectMake(_imageView.frame.origin.x,_imageViewY-scrollView.contentOffset.y,_imageView.frame.size.width
,
_imageView.frame.size.height);
}
- (UIBezierPath
*)translatedBezierPath
{
//坐标转换,原先imageView默认是以self.view作为参考系,现在要设置textView的环绕,所以将参考坐标系换成textView
CGRect
imageRect = [_myTextView
convertRect:_imageView.frame
fromView:self.view];
//将UIBezierPath设置为图片frame
UIBezierPath
*newPath = [UIBezierPath
bezierPathWithRect:imageRect];
return
newPath;
}