我試圖繪製一個(美國)足球場的iPad和iPhone設備使用UIBezierPath
,通過繪製12條水平線,其中兩個標誌着endzone的開始。使用比率使繪圖適合iPad和iPhone
正如你從下面看到的那樣,第一行從屏幕的最左邊(0)和1/12向下開始,並且一直延伸到(size.bounds.size.width)橫向。下一行從最左邊開始,但是從視圖的下方開始2/12 CGPointMake(0, self.bounds.size.height/12 *2)
等等。對於所有12行,這樣計算。我想,因爲我使用公式設置線條(即self.bounds.size.height/12),而不是整個字段適合視圖的硬數字,無論使用哪種尺寸的屏幕(iPad或蘋果手機)。
它可以在iPad上運行,然而,當我在iPhone上查看它時,它會在iPad屏幕頂部顯示一個端區,但只延伸到底部20碼線(縱向視圖)。當我在較小的iPhone屏幕(3.5英寸)中觀看時,情況更糟,因爲它只能延伸到縱向視圖底部的30碼線。
爲什麼它不按我計劃的方式發生?
更新:下面的代碼位於UIView子類中的- (void)drawRect:(CGRect)rect
方法中,名爲FieldView。我將UIView作爲屬性@property (strong, nonatomic) IBOutlet FieldView *fieldView;
連接到主視圖控制器,並在視圖控制器中調用[self.fieldView setNeedsDisplay]
,以便FieldView中的drawRect
運行。
更新2
這些三條線的高度
2014-04-14 21:47:26.783 qbgeo[2189:a0b] height 85.333336 self.bounds.size.height/12
2014-04-14 21:47:26.785 qbgeo[2189:a0b] height 170.666672 self.bounds.size.height/12 * 2
2014-04-14 21:47:26.788 qbgeo[2189:a0b] height 256.000000 self.bounds.size.height/12 * 3
UIBezierPath *goalLine = [[UIBezierPath alloc] init];
[goalLine moveToPoint:CGPointMake(0, self.bounds.size.height/12)];
[goalLine addLineToPoint: CGPointMake(self.bounds.size.width, self.bounds.size.height/12)];
[[UIColor whiteColor] setStroke];
goalLine.lineWidth = kActivationInset2;
[goalLine strokeWithBlendMode:kCGBlendModeNormal alpha:0.5];
UIBezierPath *tenYardLine = [[UIBezierPath alloc] init];
[tenYardLine moveToPoint:CGPointMake(0, self.bounds.size.height/12 *2)];
[tenYardLine addLineToPoint: CGPointMake(self.bounds.size.width, self.bounds.size.height/12 * 2)];
[[UIColor whiteColor] setStroke];
tenYardLine.lineWidth = kActivationInset2;
[tenYardLine strokeWithBlendMode:kCGBlendModeNormal alpha:0.5];
UIBezierPath *twentyYardLine = [[UIBezierPath alloc] init];
[twentyYardLine moveToPoint:CGPointMake(0, self.bounds.size.height/12 *3)];
[twentyYardLine addLineToPoint: CGPointMake(self.bounds.size.width, self.bounds.size.height/12 * 3)];
[[UIColor whiteColor] setStroke];
twentyYardLine.lineWidth = kActivationInset2;
[twentyYardLine strokeWithBlendMode:kCGBlendModeNormal alpha:0.5];
這段代碼在哪裏執行? –
@MichaelKing我用更多的信息更新了OP。 – BrainLikeADullPencil
嘗試記錄你正在創建的高度,並告訴我們它們是什麼。 –