Vis*_*ngh 4 objective-c mkmapview mkannotation ios
是否有任何方法可以将旋转视图的变换传递给其子视图?我有一个自定义MKAnnotationView,我根据用户的标题值旋转.在自定义Annotation视图类的下面的方法中,我将一个子视图添加到注释视图.
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
if(selected)
{
[self addSubview:self.myCallOutView];
return;
}
[self.myCallOutView removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
但问题是当我的注释视图旋转然后我选择任何注释时,myCallOutView也出现旋转,我不想要.我正在使用下面的线旋转自定义注释视图
[self setTransform:CGAffineTransformMakeRotation(angle * M_PI / -180.0)];
Run Code Online (Sandbox Code Playgroud)
我该如何避免这种情况?在将myCallOutView添加为子视图之前,是否需要对myCallOutView应用一些转换?
一个非常简单的解决方案是在子视图上执行反向旋转:
[self setTransform:CGAffineTransformMakeRotation(angle * M_PI / -180.0)];
// NOTE: we're using the negative of the angle here
[self.myCallOutView setTransform:CGAffineTransformMakeRotation(- angle * M_PI / -180.0)]];
Run Code Online (Sandbox Code Playgroud)
这将取消旋转对superview的影响.
替代方法:以稍微不同的方式构建您的视图:不要在视图B中使用视图A,而是将视图A和B都视为容器视图C的子视图.然后只需将您的旋转应用于视图A,B将不受影响.要在显示器上移动整个集合,请重新定位容器视图C.
归档时间: |
|
查看次数: |
1866 次 |
最近记录: |