2015-02-12 74 views
0

我創建一個用戶界面,具有綠色,超大的攝像頭開始/停止按鈕,它位於工具欄上面:創建重疊的半透明的工具欄按鈕沒有得到通過工具欄一分爲二

UI Screenshot

到目前爲止,我一直在使用yoichitgy/EEToolbarCenterButton來實現這一點,它看起來正是我最初想要的。

UI設計者特意要求該按鈕是透明的。他們還希望工具欄後面的工具欄被「剪掉」,以免在按鈕後面看到工具欄。這是按鈕應該如何工作的說明。

This is an illustration of how the button should work.

這裏是他們不想要的一個例證:

This is an illustration of what I'm not supposed to do.

所以反正是有這樣做嗎?哦,是的,還有一件事:一旦這個綠色按鈕被按下,它會變成一個更小的「停止」按鈕。停止按鈕不應該是半透明的,並且它後面的欄不應該缺少大塊。換句話說,我需要能夠打開和關閉這種行爲。

回答

0

我結束了創建自定義UIToolbar類解決這個問題我自己:

DLYCustomToolbar.h

#import <UIKit/UIKit.h> 
#import "UIToolbar+EEToolbarCenterButton.h" 

@interface DLYCustomToolbar : UIToolbar 

@property (nonatomic) bool isMasked; 

@end 

DLYCustomToolbar.m:

#import "DLYCustomToolbar.h" 

@implementation DLYCustomToolbar 

- (void) drawRect:(CGRect)rect { 
    [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5] setFill]; 
    UIRectFill(rect); 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetBlendMode(context, kCGBlendModeClear); 

    if(_isMasked) { 
     float circleDiameter = 58; 
     CGRect pathRect = CGRectMake(self.frame.size.width/2-circleDiameter/2, -circleDiameter/2+2, circleDiameter, circleDiameter); 
     UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:pathRect]; 
     [path fill]; 
    } 

    CGContextSetBlendMode(context, kCGBlendModeNormal); 
} 

- (void) setIsMasked:(bool)isMasked { 
    if (isMasked != _isMasked) { 
     _isMasked = isMasked; 
     [self setNeedsDisplay]; 
    } 
} 

@end