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;
}