UIButtons do not respond to touch after a given frame during autorotation

Hi, in my application I have some uiButtons added as subviews to the view, as in the picture below. alt text http://img99.imageshack.us/img99/5244/portraitc.png

when the user rotates the phone in landscape mode, the points of view and buttons should change position to this: alt text http://img193.imageshack.us/img193/5931/landscapeq.png

initially, when the view is in portrait mode, the buttons respond to touch. If I tilt the phone, the buttons move, everything looks fine, as in the second image, and the buttons respond to touch. If I tilt the phone back into portrait mode, the buttons will go back, they look normal, but they do not respond to touch. If I go back to the landscape, the buttons will work ...

My buttons are created as follows:

nextNewsP = [[UIButton alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 40, 10, 25, 25)];
[nextNewsP setImage:[UIImage newImageFromResource:@"next_arrow.png"] forState:UIControlStateNormal];
[nextNewsP addTarget:self action:@selector(nextNewsAction:) forControlEvents:UIControlEventTouchUpInside];
[nextNewsP setShowsTouchWhenHighlighted:TRUE];
[bottomTools addSubview:nextNewsP];
[nextNewsP release];

previousNewsP = [[UIButton alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 85, 10, 25, 25)];
[previousNewsP setImage:[UIImage newImageFromResource:@"previous_arrow.png"] forState:UIControlStateNormal];
[previousNewsP addTarget:self action:@selector(previousNewsAction:) forControlEvents:UIControlEventTouchUpInside];
[previousNewsP setShowsTouchWhenHighlighted:TRUE];
[bottomTools addSubview:previousNewsP];
[previousNewsP release];

bottomTools is a view and is added as a subtitle:

[self.view addSubview:bottomTools];
[bottomTools release];

and my toAutorotateToInterfaceOrientation function looks like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {


    [UIView beginAnimations:@"moveViews" context: nil];


    if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        NSLog(@"set frames for portrait");
        closeView.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 30, 2, 23, 25);
        newsInfo.frame = CGRectMake(10, 10, [[UIScreen mainScreen] bounds].size.width - 10, 22);
        internetActivityIndicator.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 55, 5, 18, 18);
        industryLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width/2.0 - [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width/2, 3, [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width, 22);
        bottomTools.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-40, [[UIScreen mainScreen] bounds].size.width, 40);
        nextNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 40, 10, 25, 25);
        previousNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 85, 10, 25, 25);
    }
    else
    {
        NSLog(@"set frames for landscape");
        closeView.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 30, 2, 23, 25);
        newsInfo.frame = CGRectMake(10, 10, [[UIScreen mainScreen] bounds].size.height - 10, 22);
        internetActivityIndicator.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 55, 5, 18, 18);
        industryLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height/2.0 - [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width/2, 3, [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width, 22);
        bottomTools.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.width-40, [[UIScreen mainScreen] bounds].size.height, 40);
        nextNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 40, 10, 25, 25);
        previousNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 85, 10, 25, 25);
    }

    [UIView commitAnimations];

return YES;

}

Did you have the same problem? thanks in advance, Sorin

+3
source share
3 answers

, . , , shouldAutorotateToInterfaceOrientation, , . , , .

0

( ... iOS 3.0). . , , , /. , (UIWindow) .

1/3 (.. 480-320) .

slf , .


. , viewController.view setNeedsLayout subviews viewController.view. [self.navigationController.view setNeedsLayout]. . - ControlController.view ( /). .

+1

, . [self.navigationController.view setNeedsLayout].

, (, , self.navigationController.view.frame , self.view.frame, (x = 0, y = 0, width = 320, height = 480). self.view M_PI/2 self.view.subviews, , // .

, self.view, 320. , self.navigationController.view.clipsToBounds , , self.view.

, setNeedsLayout . , - . , , SorinA , .

0
source

Source: https://habr.com/ru/post/1715515/


All Articles