HUB的offSetY属性在Y轴上的原点为屏幕Y轴方向上的中间位置,offSetY为正数时,Hub在中间位置的下方,负数时再中间位置的上方。
#pragma mark --枚举,消息提示框的位置
typedef NS_ENUM(NSInteger,MBProgressHUBPosition) {
MBProgressHUBPositionTop, //头部
MBProgressHUBPositionCenter, //中心
MBProgressHUBPositionBottom //底部
};
#pragma mark --消息提示框
+ (void)showAlertMessage:(NSString *)message toView:(UIView *)view position:(MBProgressHUBPosition)position {
[MBProgressHUD hide];
if (view == nil) {
view = [UIApplication sharedApplication].keyWindow;
}
MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:view animated:YES];
hub.userInteractionEnabled = NO;
hub.mode = MBProgressHUDModeText;
hub.labelText = message;
hub.animationType = MBProgressHUDAnimationZoomIn;
hub.margin = 10.f;
hub.opacity = 0.2;
CGFloat margin = 92 ; //距离底部和顶部的距离
CGFloat offSetY = view.bounds.size.height / 2 - margin;
if (position == MBProgressHUBPositionTop) {
hub.yOffset = -offSetY;
}
if (position == MBProgressHUBPositionCenter) {
hub.yOffset = 0;
}
if (position == MBProgressHUBPositionBottom) {
hub.yOffset = offSetY;
}
[hub hide:YES afterDelay:2.0];
}