11
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

腕立て促進アプリ「うでトレ」を作成後 また使いそうなTipsメモ

Last updated at Posted at 2016-10-28

今回は、swiftで「うでトレ」というアプリケーションを作る際に今後も使いそうだと思った部分を箇条書きベースにまとめたいと思います。

うでトレ

APP Store : https://itunes.apple.com/us/app/id1080376827
a.jpg

14633403_730245973796332_7740104976827374543_o.jpg

腕立て促進アプリ「うでトレ」

これで1人で筋トレする時も
かわいい女の子に応援され、回数も数えてもらえます。

【こんな方にオススメ!】
・筋トレが長く続かない!
・学生の頃の部活みたいに誰かに声かけ 応援 してほしい!
・楽しく筋トレしたい!
・かっこいい体が欲しい!
・太い腕を手に入れたい!

【機能】
・main.storyboardのViewを最前面にレイヤー移動

main.storyboardのViewを最前面にレイヤー移動
var fetchedView = self.view.viewWithTag(1) //viewの中のtagが
self.view.bringSubviewToFront(fetchedView!) //fetchedViewを最前面へ

・SNSで今までした回数をみんなにShare

SNSで今までした回数をみんなにShare
@IBAction func SNSAction(sender: AnyObject) {
        //選択肢の上に表示するアラート
        let alert = UIAlertController(title: "SNSに投稿",message: nil, preferredStyle: .ActionSheet)//選択肢設定
        let firstAction = UIAlertAction(title: "Facebook", style: .Default){
            action in
            // Facebookの投稿ダイアログを作って
            let cv = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
            
            cv.setInitialText("#うでとれ #ゆかちぃ")
            cv.addImage(UIImage(named: "SNS.jpg"))
            // 投稿ダイアログを表示する
            self.presentViewController(cv, animated: true, completion: nil)
            
        }
        let secondAction = UIAlertAction(title: "Twitter", style: .Default){
            action in
            // Twitterの投稿ダイアログを作って
            let cv = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
            // 文字を追加
            cv.setInitialText("みんな聞いて!\n私の彼は" + String (NSUserDefaults.standardUserDefaults().integerForKey("U") ) + "回も腕立してるの! " + "#うでとれ#ゆかちぃ")
            cv.addImage(UIImage(named: "SNS.jpg"))
            // 投稿ダイアログを表示する
            self.presentViewController(cv, animated: true, completion:nil )
        }
        let cancelAction = UIAlertAction(title: "キャンセル", style: .Default,handler : nil)
        //選択肢をアラートに登録
        alert.addAction(firstAction)
        alert.addAction(secondAction)
        alert.addAction(cancelAction)
        //アラートを表示
        presentViewController(alert, animated: true, completion: nil)
}

・アニメーション

アニメーション
class func AnimationImg(img : UIImageView){
        img.transform = CGAffineTransformMakeScale(0.2, 0.2)
        img.alpha = 0 // imgはUIImageView
        UIView.animateWithDuration(2.0,
            delay: 0.1,
            usingSpringWithDamping: 0.8,
            initialSpringVelocity: 3.0,
            options: UIViewAnimationOptions.AllowUserInteraction,
            animations: {
                img.alpha = 1.0
                img.transform = CGAffineTransformIdentity
            }, completion: nil)
}

・UIAlertControllerに画像をAddSubView

UIAlertControllerにAddSubView
let v = UIImageView(frame: CGRectMake(0 , -190, 270, 180 ))
v.image = UIImage(named: "GJ.jpg")
v.layer.cornerRadius = 20
v.contentMode = UIViewContentMode.ScaleAspectFill
v.clipsToBounds = true
alert.view.addSubview(v)

・アプリアイコン での 3D Touch対応

UIAlertControllerにAddSubView
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        let shortcut1 = UIMutableApplicationShortcutItem(type: "com.mycompany.myapp.quick", localizedTitle: "Quick Start", localizedSubtitle: "OP Skip", icon: UIApplicationShortcutIcon(templateImageName: "QS"), userInfo:["value1":"key1"])
        let shortcut2 = UIMutableApplicationShortcutItem(type: "com.mycompany.myapp.reset", localizedTitle: "Data Reset", localizedSubtitle: "腕立て回数の初期化", icon: UIApplicationShortcutIcon(templateImageName: "DR"), userInfo:["value1":"key1"])        
        // 登録
        UIApplication.sharedApplication().shortcutItems = [shortcut1,shortcut2]
        return true
    }
    
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
if let _ : UIApplicationShortcutItem = shortcutItem {
        //3D Touch Action 起動時の分岐
        if shortcutItem.type == "com.mycompany.myapp.quick" {
                //windowを生成
                self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
                //Storyboardを指定
                let storyboard = UIStoryboard(name: "Main", bundle: nil)//Viewcontrollerを指定
                let initialViewController = storyboard.instantiateViewControllerWithIdentifier("Menu")
                //rootViewControllerに入れる
                self.window?.rootViewController = initialViewController
                //表示
                self.window?.makeKeyAndVisible()
        }
        if shortcutItem.type == "com.mycompany.myapp.reset"{
                // 保存データを全削除
                let appDomain:String = NSBundle.mainBundle().bundleIdentifier!
                NSUserDefaults.standardUserDefaults().removePersistentDomainForName(appDomain)
            }
        }
    }

雑文失礼しました。

11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?