我正在尝试从另一个名为DownViewController的viewcontroller移动SensorViewController框架。我创建了一个委托对象并尝试更改框架,但它没有改变。
AppDelegate.h
#import <UIKit/UIKit.h>
#import "SensorsViewController.h"
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) SensorsViewController *sensorViewController;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
@synthesize sensorViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sensorViewController = [[SensorsViewController alloc] initWithNibName:@"SensorsViewController" bundle:[NSBundle mainBundle]];
}
DownViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
// Do any additional setup after loading the view from its nib.
}
- (void)keyboardDidShow:(NSNotification *)notification
{
//Assign new frame to your view
AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
// the following part should change SensorViewController but, it is not!
[[appDelegate sensorViewController].view setFrame:CGRectMake(0,-260,1030,768)];
}
-(void)keyboardDidHide:(NSNotification *)notification
{
[self.view setFrame:CGRectMake(0,0,1030,768)];
}