在IOS 7中阻止不被调用而不是动画

时间:2013-10-09 08:48:44

标签: iphone ios ios7 objective-c-blocks cgaffinetransform

我在我的应用中使用 ShakingAlertView

https://github.com/lukestringer90/ShakingAlertView

它在IOS 6中完美运行。但在我更新到IOS 7之后,它没有动画,并且没有调用错误处理的块函数。 下面给出了摇动警报视图初始化的代码。

currentPass = [[ShakingAlertView alloc]initWithAlertTitle:@"Enter Current Password" checkForPassword:self.pass
                                                        usingHashingTechnique:HashTechniqueMD5
                                                        onCorrectPassword:^{
                                                            isCurrentPassConfirmed = YES;
                                                            [self._accountSource willScrollToTop];
                                                            self.password.text = @"";
                                                            [self.password becomeFirstResponder];

                                                        } onDismissalWithoutPassword:^{
                                                            //NSLog(@"hi");
                                                            [self showFailedPasswordAlert];

                                                        }];
    currentPass.alertViewStyle = UIAlertViewStyleSecureTextInput;
    [currentPass show];

下面是为摇动效果设置动画的方法。这是正确调用但没有效果。

- (void)animateIncorrectPassword {
    // Clear the password field
    _passwordField.text = nil;

    // Animate the alert to show that the entered string was wrong
    // "Shakes" similar to OS X login screen
    CGAffineTransform moveRight = CGAffineTransformTranslate(CGAffineTransformIdentity, 20, 0);
    CGAffineTransform moveLeft = CGAffineTransformTranslate(CGAffineTransformIdentity, -20, 0);
    CGAffineTransform resetTransform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 0);

    [UIView animateWithDuration:0.1 animations:^{
        // Translate left
        self.transform = moveLeft;

    } completion:^(BOOL finished) {

        [UIView animateWithDuration:0.1 animations:^{

            // Translate right
            self.transform = moveRight;

        } completion:^(BOOL finished) {

            [UIView animateWithDuration:0.1 animations:^{

                // Translate left
                self.transform = moveLeft;

            } completion:^(BOOL finished) {

                [UIView animateWithDuration:0.1 animations:^{

                    // Translate to origin
                    self.transform = resetTransform;
                }];
            }];

        }];
    }];

}

请帮帮我。

2 个答案:

答案 0 :(得分:2)

iOS7不允许您自定义UIAlertview

  1. 更好地创建UIView的自定义视图子类,它是绘制的     使用- (void)drawRect:(CGRect)rect方法以编程方式查看。

  2. 再创建一个容器类(继承自NSObject) 用于创建和绑定您的标题/密码和确定按钮     将自定义委托属性添加到自定义警报中     所以我们可以实现我们的自定义委托方法     clickedButtonAtIndex方法。

  3. 据我所知,iOS7中的块/动画没有变化。

  4. 或参考此链接https://github.com/wimagguc/ios-custom-alertview

答案 1 :(得分:1)

UIAlertView的布局大幅改变是iOS 7,几乎不可能自定义和更改。你将不得不想出一个新的解决方案。