Skip to content

Commit

Permalink
Merge pull request #151 from christiancabarrocas/SmallRefactor
Browse files Browse the repository at this point in the history
Small refactor
  • Loading branch information
vikmeup committed Apr 1, 2016
2 parents 47bcd52 + 7ef0128 commit 21e4561
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
23 changes: 11 additions & 12 deletions SCLAlertView/SCLAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 13 additions & 12 deletions SCLAlertViewTests/SCLButtonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -78,21 +78,22 @@ 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") {}
let button = alert.buttons[0]
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
//}

0 comments on commit 21e4561

Please sign in to comment.