我正在使用UIRotationGestureRecognizer旋转图像。我想将旋转角度从“弧度”转换为“度”,因为我可以更好地考虑度。我在堆栈和其他来源上找到了解决方案,但由于某种原因,该解决方案似乎无法正常工作
例如,当我逆时针旋转图像约45度时,从公式中获得的度值约为-0.15?
//removed some code
CreateMap<CarModel, CarDTO>
.ForMember(dst => dst.CarBodyType, opt => opt.MapFrom((detail, dto, _, context) => ResolveEnumTranslation(detail, context, car => car.CarBodyType)))
.ForMember(dst => dst.FuelType, opt => opt.MapFrom((detail, dto, _, context) => ResolveEnumTranslation(detail, context, car => car.FuelType)))
.ForMember(dst => dst.GearType, opt => opt.MapFrom((detail, dto, _, context) => ResolveEnumTranslation(detail, context, car => car.GearType)))
//removed more for clearity (there are more enums)
private string ResolveEnumTranslation(CarDetail carDetail, ResolutionContext context, Func<CarDetail, object> property)
{
var selectedEnum = property.Invoke(carDetail);
if (context.Items.TryGetValue(localeKey, out var locale) && locale is string localeString)
{
return carDetail.Country.Translations
.FirstOrDefault(t => t.EnumType == selectedEnum.GetType().Name
&& t.EnumValue == (int)selectedEnum
&& string.Equals(t.CountryLocale?.Locale, localeString, StringComparison.OrdinalIgnoreCase))
?.TranslatedValue ?? property.Invoke(carDetail).ToString();
}
return selectedEnum.ToString();
}
答案 0 :(得分:0)
您的主要问题是您正在重置手势的sender.rotation = 0
属性。你不应该那样做。从文档中:
旋转值是随时间变化的单个值。这不是上次报告旋转以来的增量值。首次识别手势时,将旋转值应用于视图状态-请勿在每次调用处理程序时将旋转值连接起来。
因此删除imageView.transform = imageView.transform.rotated(by: sender.rotation)
行。
因此,您需要修复将变换应用于图像视图的方式。
替换:
imageView.transform = CGAffineTransform(rotatationAngle: sender.rotation)
具有:
<input type="text" formControlName="country_id">
这将应用完整旋转,而不是尝试增加当前旋转。