diff --git a/SCLAlertView/SCLAlertView.swift b/SCLAlertView/SCLAlertView.swift index 07bd91d..c9f8afd 100644 --- a/SCLAlertView/SCLAlertView.swift +++ b/SCLAlertView/SCLAlertView.swift @@ -360,18 +360,17 @@ public class SCLAlertView: UIViewController { func keyboardWillShow(notification: NSNotification) { keyboardHasBeenShown = true - if let userInfo = notification.userInfo { - if let beginKeyBoardFrame = userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue.origin.y { - if let endKeyBoardFrame = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.origin.y { - tmpContentViewFrameOrigin = self.contentView.frame.origin - tmpCircleViewFrameOrigin = self.circleBG.frame.origin - let newContentViewFrameY = beginKeyBoardFrame - endKeyBoardFrame - self.contentView.frame.origin.y - let newBallViewFrameY = self.circleBG.frame.origin.y - newContentViewFrameY - self.contentView.frame.origin.y -= newContentViewFrameY - self.circleBG.frame.origin.y = newBallViewFrameY - } - } - } + + guard let userInfo = notification.userInfo else {return} + guard let beginKeyBoardFrame = userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue.origin.y else {return} + guard let endKeyBoardFrame = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.origin.y else {return} + + tmpContentViewFrameOrigin = self.contentView.frame.origin + tmpCircleViewFrameOrigin = self.circleBG.frame.origin + let newContentViewFrameY = beginKeyBoardFrame - endKeyBoardFrame - self.contentView.frame.origin.y + let newBallViewFrameY = self.circleBG.frame.origin.y - newContentViewFrameY + self.contentView.frame.origin.y -= newContentViewFrameY + self.circleBG.frame.origin.y = newBallViewFrameY } func keyboardWillHide(notification: NSNotification) { diff --git a/SCLAlertViewTests/SCLButtonTests.swift b/SCLAlertViewTests/SCLButtonTests.swift index 9d42f3c..8c9c102 100644 --- a/SCLAlertViewTests/SCLButtonTests.swift +++ b/SCLAlertViewTests/SCLButtonTests.swift @@ -54,7 +54,7 @@ class SCLButtonTests: XCTestCase { func testButtonTargets() { let alert = SCLAlertView() - alert.addButton("testButtontitle") {} + alert.addButton("testButtonTitle") {} let buttonTargets = alert.buttons[0].allTargets().first let button = alert.buttons[0] @@ -78,6 +78,18 @@ class SCLButtonTests: XCTestCase { XCTAssertTrue(buttonActionsTouchUpOutside![0] == "buttonRelease:") } + func testButtonSelectorAndTarget() { + let alert = SCLAlertView() + let testTarget = SCLAlertView() + let testSelector = Selector() + alert.addButton("testButtonTitle", target: testTarget, selector: testSelector) + let button = alert.buttons[0] + XCTAssertTrue(button.target.isKindOfClass(SCLAlertView.self)) + XCTAssertTrue(button.selector == testSelector) + XCTAssertTrue(button.actionType == SCLActionType.Selector) + + } + func testButtonActionType() { let alert = SCLAlertView() alert.addButton("testButtonTitle") {} @@ -85,14 +97,3 @@ class SCLButtonTests: XCTestCase { XCTAssertTrue(button.actionType == SCLActionType.Closure) } } - - -//public func addButton(title:String, action:()->Void)->SCLButton { -// let btn = addButton(title) -// btn.actionType = SCLActionType.Closure -// btn.action = action -// btn.addTarget(self, action:Selector("buttonTapped:"), forControlEvents:.TouchUpInside) -// btn.addTarget(self, action:Selector("buttonTapDown:"), forControlEvents:[.TouchDown, .TouchDragEnter]) -// btn.addTarget(self, action:Selector("buttonRelease:"), forControlEvents:[.TouchUpInside, .TouchUpOutside, .TouchCancel, .TouchDragOutside] ) -// return btn -//} \ No newline at end of file