貓貓學iOS之ipad開發Popover的調色盤應用_popover顯示後其他控制項仍然能進行互動

來源:互聯網
上載者:User

貓貓學iOS之ipad開發Popover的調色盤應用_popover顯示後其他控制項仍然能進行互動

 

一:效果

後面的是xcode的控制台

二:代碼ViewController
#import ViewController.h#import ColorsViewController.h@interface ViewController () - (IBAction)buttonClick:(UIButton *)btn;@property (nonatomic, weak) UIButton *colorButton;@property (nonatomic, strong) UIPopoverController *popover;@property (weak, nonatomic) IBOutlet UIButton *greenButton;- (IBAction)greenButtonClick;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];}- (IBAction)greenButtonClick {    NSLog(@greenButtonClick);}- (IBAction)buttonClick:(UIButton *)btn {    // 0.內容    ColorsViewController *colors = [[ColorsViewController alloc] init];    colors.delegate = self;    // 1.建立    self.popover = [[UIPopoverController alloc] initWithContentViewController:colors];    self.popover.delegate = self;    // 2.顯示//    [self.popover presentPopoverFromRect:CGRectMake(150, 150, 100, 100) inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];    [self.popover presentPopoverFromRect:CGRectMake(924, 668, 100, 100) inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];//    [self.popover presentPopoverFromRect:btn.bounds inView:btn permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];//    [self.popover presentPopoverFromRect:btn.frame inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];    // 3.設定哪裡控制項在popover顯示出來的時候,仍舊可以跟使用者進行互動    self.popover.passthroughViews = @[self.greenButton];    self.colorButton = btn;}#pragma mark - 顏色選擇代理- (void)colorsViewController:(ColorsViewController *)vc didSelectColor:(UIColor *)color{    self.colorButton.backgroundColor = color;    // 關閉popover    [self.popover dismissPopoverAnimated:YES];}#pragma mark - popover的代理- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{    NSLog(@popover銷毀了);}@end
ColorsViewController
#import @class ColorsViewController;@protocol ColorsViewControllerDelegate @optional- (void)colorsViewController:(ColorsViewController *)vc didSelectColor:(UIColor *)color;@end@interface ColorsViewController : UITableViewController@property (nonatomic, weak) id delegate;@end
#import ColorsViewController.h@interface ColorsViewController ()@end@implementation ColorsViewController- (void)viewDidLoad {    [super viewDidLoad];    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}#pragma mark - Table view data source- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {    return 30;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *ID = @cell;    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];    if (!cell) {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];        cell.selectionStyle = UITableViewCellSelectionStyleNone;    }    cell.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1.0];    return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    if ([self.delegate respondsToSelector:@selector(colorsViewController:didSelectColor:)]) {        UIColor *color = [tableView cellForRowAtIndexPath:indexPath].backgroundColor;        [self.delegate colorsViewController:self didSelectColor:color];    }}@end

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.