0
3.5 및 4 인치 화면에서 잘 작동하는 앱에서 진행률 표시 줄이 있지만 iPhone 6 및 6 Plus 용 앱 업데이트 프로세스가 시작되었습니다. 진도 원이 의도 한대로 기능하지 않는다는 것을 알았습니다.새 화면 크기의 중앙 처리 진행 원 표시
이유는 작은 화면의 중앙에 서서 진행 상황 위치를 하드 코딩했기 때문입니다.
아무도 화면 크기와 상관없이 원을 중심으로 변환하기 위해 수행해야 할 작업을 표시 할 수 있는지 궁금합니다.
class ProgressCircle: UIView {
override func drawRect(rect: CGRect) {
var ctx = UIGraphicsGetCurrentContext()
var innerRadiusRatio: CGFloat = 0.6
var path: CGMutablePathRef = CGPathCreateMutable()
var startAngle: CGFloat = CGFloat(-M_PI_2)
var endAngle: CGFloat = CGFloat(-M_PI_2) + min(1.0, progress) * CGFloat(M_PI * 2)
var outerRadius: CGFloat = CGRectGetWidth(self.bounds) * 0.5 - 1.0
var innerRadius: CGFloat = outerRadius * innerRadiusRatio
var center = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect))
//Code for background circle
var context: CGContextRef = UIGraphicsGetCurrentContext()
colourTheme = NSUserDefaults.standardUserDefaults().integerForKey("themeSettings")
if colourTheme == 1 {
CGContextSetFillColorWithColor(context, (UIColorFromRGB(0xEAEAEA)).CGColor)
} else {
CGContextSetFillColorWithColor(context, (UIColor.darkGrayColor()).CGColor)
}
var rectangle: CGRect = CGRectMake(0, 0, 171, 171)
CGContextBeginPath(context)
CGContextAddEllipseInRect(context, rectangle)
CGContextDrawPath(context, kCGPathFill)
UIGraphicsEndImageContext()
if colourTheme == 1 {
CGContextSetFillColorWithColor(context, (UIColor.darkGrayColor()).CGColor)
} else {
CGContextSetFillColorWithColor(context, (UIColorFromRGB(0xEAEAEA)).CGColor)
}
var rectangleSmall: CGRect = CGRectMake(35.95, 35.95, 99.1, 99.1) //102.6
CGContextBeginPath(context)
CGContextAddEllipseInRect(context, rectangleSmall)
CGContextDrawPath(context, kCGPathFill)
UIGraphicsEndImageContext()
//Code for progress radius
CGPathAddArc(path, nil, center.x, center.y, innerRadius, startAngle, endAngle, false)
CGPathAddArc(path, nil, center.x, center.y, outerRadius, endAngle, startAngle, true)
CGPathCloseSubpath(path)
CGContextAddPath(ctx, path)
CGContextSaveGState(ctx)
CGContextClip(ctx)
if percent > 100 {
CGContextDrawImage(ctx, self.bounds, UIImage(named: "RadialProgressFillOver").CGImage)
} else {
CGContextDrawImage(ctx, self.bounds, UIImage(named: "RadialProgressFill").CGImage)
}
CGContextRestoreGState(ctx)
}
: 여기
내가 해낸 솔루션입니다. 프로그래밍 방식으로 그렇게 결정 했습니까? – davidrayowens어떻게이 화면을 화면에 표시하고 있습니까? – rdelmar
@dvdowns 예, AutoLayout을 사용해 보았는데 정말 마음에 들지 않습니다. 내 애플 리케이션에 이렇게 많은 요소가 없기 때문에 별도의 스토리 보드를 사용하는 것이 더 나은 해결책이 될 것이라고 판단했습니다. – user3746428