Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在iOS中旋转视图会导致UIImageView高度问题_Iphone_Ios_Objective C - Fatal编程技术网

Iphone 在iOS中旋转视图会导致UIImageView高度问题

Iphone 在iOS中旋转视图会导致UIImageView高度问题,iphone,ios,objective-c,Iphone,Ios,Objective C,我一直在为iOS编写一个应用程序,我正在尝试实现横向视图。我试图同时支持iOS 5和iOS 6,因此禁用了自动布局。当我旋转到横向时,布局加载正确。然后我旋转到横向,当我旋转回纵向时,包含我的徽标的UIImageView延伸到我的按钮和另一个标签下面 从ViewController.m: @interface ViewController () - (IBAction)showMenu:(id)sender; @end @implementation ViewController @sy

我一直在为iOS编写一个应用程序,我正在尝试实现横向视图。我试图同时支持iOS 5和iOS 6,因此禁用了自动布局。当我旋转到横向时,布局加载正确。然后我旋转到横向,当我旋转回纵向时,包含我的徽标的UIImageView延伸到我的按钮和另一个标签下面

从ViewController.m:

@interface ViewController ()

- (IBAction)showMenu:(id)sender;

@end

@implementation ViewController

@synthesize start, menuButton, vector_status, login_status, items, recordLength, countdown, change_name, iapi, running, timeOver, setupDone, dfm, motionmanager, locationManager, recordDataTimer, timer, testLength, expNum, sampleInterval, sessionName,geoCoder,city,country,address,dataToBeJSONed,elapsedTime,recordingRate, experiment,firstName,lastInitial,userName,useDev,passWord,session_num,managedObjectContext,dataSaver,x,y,z,mag,image ;

// displays the correct xib based on orientation and device type - called automatically upon view controller entry
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad) {
        if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
            [[NSBundle mainBundle] loadNibNamed:@"ViewController~landscape_iPad"
                                          owner:self
                                        options:nil];
            [self viewDidLoad];
        } else {
            [[NSBundle mainBundle] loadNibNamed:@"ViewController_iPad"
                                          owner:self
                                        options:nil];
            [self viewDidLoad];
        }
    } else {
        if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
            [[NSBundle mainBundle] loadNibNamed:@"ViewController~landscape_iPhone"
                                          owner:self
                                        options:nil];
            [self viewDidLoad];
        } else {
            [[NSBundle mainBundle] loadNibNamed:@"ViewController_iPhone"
                                          owner:self
                                        options:nil];
            [self viewDidLoad];
        }

    }



}

// pre-iOS6 rotating options
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

// iOS6 rotating options
- (BOOL)shouldAutorotate {
    return YES;
}

// iOS6 interface orientations
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}


- (void)viewDidLoad {

    [super viewDidLoad];
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    [start addGestureRecognizer:longPress];

    recordLength = 10;
    countdown = 10;

    useDev = TRUE;

    self.navigationItem.rightBarButtonItem = menuButton;
    iapi = [iSENSE getInstance];
    [iapi toggleUseDev: useDev];


    running = NO;
    timeOver = NO;
    setupDone = NO;

    if (useDev) {
        expNum = DEV_DEFAULT_EXP;
    } else {
        expNum = PROD_DEFAULT_EXP;
    }

    dfm = [[DataFieldManager alloc] init];
    //[dfm setEnabledField:YES atIndex:fACCEL_Y];
    motionmanager = [[CMMotionManager alloc] init];

    userName = @"sor";
    passWord = @"sor";
    firstName = @"No Name";
    lastInitial = @"Provided";
    [self login:@"sor" withPassword:@"sor"];

    if (managedObjectContext == nil) {
        managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
    }

    // DataSaver from Data_CollectorAppDelegate
    if (dataSaver == nil) {
        dataSaver = [(AppDelegate *) [[UIApplication sharedApplication] delegate] dataSaver];
        NSLog(@"Datasaver Details: %@", dataSaver.description);
        NSLog(@"Current count = %d", dataSaver.count);
    }


}

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if (self.isMovingToParentViewController == YES) {
        change_name = [[CODialog alloc] initWithWindow:self.view.window];
        change_name.title = @"Enter First Name and Last Initial";
        [change_name addTextFieldWithPlaceholder:@"First Name" secure:NO];
        [change_name addTextFieldWithPlaceholder:@"Last Initial" secure:NO];
        UITextField *last = [change_name textFieldAtIndex:1];
        [last setDelegate:self];
        [change_name addButtonWithTitle:@"Done" target:self selector:@selector(changeName)];
        [change_name showOrUpdateAnimated:YES];


        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

        BOOL x1 = [prefs boolForKey:@"X"];
        BOOL y1 = [prefs boolForKey:@"Y"];
        BOOL z1 = [prefs boolForKey:@"Z"];
        BOOL mag1 = [prefs boolForKey:@"Magnitude"];


        if (x)
            x = x1;
        if (y)
            y = y1;
        if (z)
            z = z1;
        if (mag)
            mag = mag1;

        [self willRotateToInterfaceOrientation:(self.interfaceOrientation) duration:0];
        NSLog(@"Frog FROG FROG");

        /*[image setAutoresizesSubviews:YES];
        image.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

        */
    }
}
从AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
    }    
    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    navigation.navigationBar.barStyle = UIBarStyleBlackOpaque;
    self.window.rootViewController = navigation;
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs setBool:YES forKey:@"Y"];
    self.viewController.setupDone = YES;
    [self.window makeKeyAndVisible];
    return YES;
}

检查该UIImageView的
autoResizingMask
属性。您应该首先查看UIViewAutoresizingFlexibleHeight。

检查UIImageView的autoresizingMask属性或通过Interface Builder。设置该属性后,图像将完全消失。以前,它在那里,但是UIImageView被拉伸了。我的意思是你必须取消设置错误的autoResizingMask设置。首先检查UIViewAutoresizingFlexibleHeight。你能将其作为答案发布,以便我可以接受吗?谢谢你的帮助。