iPhone UIButton Flip and Expand

时间:2012-08-12 14:24:36

标签: iphone objective-c uibutton uiviewanimation uiviewanimationtransition

我正在尝试将一个简单的按钮设置为更改大小并进行扩展,然后在后续点击时缩小。

它有点工作,翻转后的最后一个按钮看起来是正确的 - 它是圆形的和不同的大小。问题是在过渡期间,我得到了这种奇怪的非圆形效果。有关此问题的信息,请参阅此链接 - > http://screencast.com/t/rJaSJ0nGq

如何使过渡平滑并始终呈圆形?我不想要在截屏视频中出现圆角矩形外观。

这是我按下按钮的方法:

// Handle when a user presses the button
- (IBAction)bubblePressed:(id)sender {

    // Expand the bubble if it's pressed or de-expand it if
    // already expanded
    if ( buttonResized ) {

        CGRect tempFrame=self.expandMe.frame;
        tempFrame.size.width=100;//change acco. how much you want to expand
        tempFrame.size.height=100;
        [UIView beginAnimations:@"" context:nil];
        [UIView setAnimationDuration:BUTTON_FLIP_TIME];
        self.expandMe.frame=tempFrame;

        // Round the buttons
        self.expandMe.clipsToBounds = YES;
        self.expandMe.layer.cornerRadius = self.expandMe.frame.size.width / 2;//half of the width
        self.expandMe.layer.borderColor=[UIColor clearColor].CGColor;
        self.expandMe.layer.borderWidth=2.0f;

        // Flip the button
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.expandMe cache:YES];

        [UIView commitAnimations];

    }
    else {

        CGRect tempFrame=self.expandMe.frame;
        tempFrame.size.width=200;//change acco. how much you want to expand
        tempFrame.size.height=200;
        [UIView beginAnimations:@"" context:nil];
        [UIView setAnimationDuration:BUTTON_FLIP_TIME];
        self.expandMe.frame=tempFrame;

        // Round the buttons
        self.expandMe.clipsToBounds = YES;
        self.expandMe.layer.cornerRadius = self.expandMe.frame.size.width / 2;//half of the width
        self.expandMe.layer.borderColor=[UIColor clearColor].CGColor;
        self.expandMe.layer.borderWidth=2.0f;

        // Flip the button
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.expandMe cache:YES];

        [UIView commitAnimations];

    }

    // Flip the variable that tracks flipping
    buttonResized = !buttonResized;

}

1 个答案:

答案 0 :(得分:0)

最后我发现了这个 - > https://github.com/ole/OBShapedButton。这是一个很棒的课程和MIT许可。