在区域更改后,我尝试了以下内容来获取MKMapView的实际可见区域。在用户旋转地图 后,无生成所需结果 。
#1 and #2 come from this post,所有3个工作都很好,直到用户旋转地图,通过更改其标题使mapView.camera发挥作用。发生这种情况后,mapView.visibleRect与实际可见区域不匹配。我确信改变高度和音高会有类似的问题。我理解为什么MKMapView上的属性一旦进入3D就没有意义,但我不知道如何解释mapView.camera。在this post中对其中一个建议答案的评论中提到了这一点,但没有提供解决方案。
我的问题是,如何通过mapView.camera获取 对用户 实际可见的区域,并考虑标题,海拔高度和音高?
答案 0 :(得分:2)
我正在寻找类似情况的答案,并找到this。对于我的项目,我解决了以下问题。希望这会有所帮助。
public class CustomClass {
private ProgressBar mProgressBar;
private FloatingActionButton mFab;
private RelativeLayout parentLayout;
private LayoutInflater inflater;
private static CustomClass custom;
private CustomClass (Context context) {
findViewsById(context);
}
private CustomClass (View view) {
findViewsById(view);
}
public static CustomClass getInstance(Context context, View view) {
custom = new CustomClass (view);
custom.setPColor(context);
return custom;
}
public static CustomClass getInstance(Context context) {
custom = new CustomClass (context);
custom.setPColor(context);
return custom;
}
private void setPColor(Context context) {
if (mProgressBar != null)
mProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.bluecolor), android.graphics.PorterDuff.Mode.MULTIPLY);
}
private void findViewsById(View view) {
if (view != null) {
mProgressBar = (ProgressBar) view.findViewById(R.id.custom_progressbar);
mFab = (FloatingActionButton) view.findViewById(R.id.custom_floatingActionButton);
parentLayout = (RelativeLayout) view.findViewById(R.id.rl_progress_fab_container);
}
}
private void findViewsById(Context context) {
Activity activity = (Activity) context;
if (activity != null) {
mProgressBar = (ProgressBar) activity.findViewById(R.id.custom_progressbar);
mFab = (FloatingActionButton) activity.findViewById(R.id.custom_floatingActionButton);
parentLayout = (RelativeLayout) activity.findViewById(R.id.rl_progress_fab_container);
}
}
public void show() {
if (custom.parentLayout != null)
custom.parentLayout.setVisibility(View.VISIBLE);
}
public void hide() {
if (custom.parentLayout != null)
custom.parentLayout.setVisibility(View.GONE);
}