旋转

时间:2015-11-11 16:20:56

标签: popover

我想在使用UItableViewController按下按钮时显示popoverPresentationController

如果设备没有旋转,它可以正常工作,但如果设备被旋转preferredContentSize就不行了。

代码:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end

#import "ViewController.h"
#import "TableViewController.h"

@interface ViewController () <UIAdaptivePresentationControllerDelegate>

@end

@implementation ViewController

- (IBAction)showActionButtonPress:(id)sender {

    TableViewController *tableViewController = [[self storyboard] instantiateViewControllerWithIdentifier:@"TableViewController"];

    tableViewController.modalPresentationStyle = UIModalPresentationPopover;
    tableViewController.popoverPresentationController.sourceView = sender;
    tableViewController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown;

    UIPresentationController *presentationController = tableViewController.presentationController;
    presentationController.delegate = self;

    tableViewController.preferredContentSize = CGSizeMake(414.0, 174.0);

    [self presentViewController:tableViewController animated:YES completion:nil];
}



#pragma mark - <UIAdaptivePresentationControllerDelegate>
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
    NSLog(@"%@: %@", NSStringFromSelector(_cmd), self);
    return UIModalPresentationNone;
}

@end




#import <UIKit/UIKit.h>

@interface TableViewController : UITableViewController

@end

#import "TableViewController.h"
#import "TableViewCell.h"

@implementation TableViewController

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    //  return 210;
    return UITableViewAutomaticDimension;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    //return UITableViewAutomaticDimension;
    return 174.0;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%@: %@", NSStringFromSelector(_cmd), self);

    NSString *CellIdentifier =  @"CellIdentifier";

    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell.imageView.image = [UIImage imageNamed:@"ball.png"];

    cell.label1.text = @"One";
    cell.label2.text = @"Two";
    cell.label3.text = @"Three";
    cell.label4.text = @"Four";

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

@end


#import <UIKit/UIKit.h>

@interface TableViewCell : UITableViewCell

@property (nonatomic, strong) IBOutlet UIImageView *cellImageView;
@property (nonatomic, strong) IBOutlet UILabel *label1;
@property (nonatomic, strong) IBOutlet UILabel *label2;
@property (nonatomic, strong) IBOutlet UILabel *label3;
@property (nonatomic, strong) IBOutlet UILabel *label4;

@end

#import "TableViewCell.h"

@implementation TableViewCell

@end

图片肖像:

Image Portrait

Image LandScape:

Image LandScape

0 个答案:

没有答案