简体   繁体   English

iPhone子视图在2个视图之间翻转

[英]iPhone subview flip between 2 views

iPhone / Objective-C iPhone / Objective-C

On my view a little "hover" view appears after a user clicks on a button on the main view. 在我的视图中,用户单击主视图上的按钮后会出现一个小“悬停”视图。 When the user clicks this subview I want the subview to FlipFromRight to another view (same size). 当用户单击此子视图时,我希望子视图FlipFromRight到另一个视图(相同大小)。 The main view underneath should stay. 下面的主视图应该保留。

viewHot and viewCold are the subviews viewMain is the main one. viewHotviewCold是子视图viewMain是主要视图。

Is this possible? 这可能吗?

Create another empty view in viewMain called viewHover and position it where you want the hover views to show. 在viewMain中创建另一个名为viewHover的空视图,并将其放置在您希望显示悬停视图的位置。 Then in IB add either viewHot or viewCold (not both) as a subview of viewHover. 然后在IB中添加viewHot或viewCold(不是两者)作为viewHover的子视图。

Then call a method like this to flip the views: 然后调用这样的方法来翻转视图:

-(void)flipViews
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];  
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:viewHover cache:YES];

    if ([viewHot superview])
    {
        [viewHot removeFromSuperview];
        [viewHover addSubview:viewCold];
        [viewHover sendSubviewToBack:viewHot];
    }
    else
    {
        [viewCold removeFromSuperview];
        [viewHover addSubview:viewHot];
        [viewHover sendSubviewToBack:viewCold];
    }

    [UIView commitAnimations];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM