iOS中制作微信摇一摇的图框雏形

原创 2016年05月30日 15:17:56

模拟一下微信摇一摇的时候,两个图片上下滑动开,中间露出一朵小花的操作。

在这里用到的是触摸事件

对应的方法提示为:

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">- (</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">void</span><span style="font-variant-ligatures: no-common-ligatures">)motionBegan:(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">UIEventSubtype</span><span style="font-variant-ligatures: no-common-ligatures">)motion withEvent:(</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIEvent</span><span style="font-variant-ligatures: no-common-ligatures"> *)event</span></p>

动画的方法:

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">[UIView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">animateWithDuration</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">1.5</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">animations</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:^{</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000"></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">     //先完成一个操作</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">}</span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">completion</span><span style="font-variant-ligatures: no-common-ligatures">:^(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">BOOL</span><span style="font-variant-ligatures: no-common-ligatures"> finished) {</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">     //上面的操作完成后来完成这里面的操作</span></p>}];


transform方法

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures">CGAffineTransformMakeTranslation</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">)</span></p>

下面是实现的代码:

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">- (</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">void</span><span style="font-variant-ligatures: no-common-ligatures">)loadView{</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">    [</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">super</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">loadView</span><span style="font-variant-ligatures: no-common-ligatures">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">imageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = [[</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">alloc</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">] </span><span style="font-variant-ligatures: no-common-ligatures">initWithFrame</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:[</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIScreen</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">mainScreen</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">].</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">bounds</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">imageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures">backgroundColor</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIColor</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">whiteColor</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-variant-ligatures: no-common-ligatures">//    self.imageView.alpha = 0.1;</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">    [</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">view</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">addSubview</span><span style="font-variant-ligatures: no-common-ligatures">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">imageView</span><span style="font-variant-ligatures: no-common-ligatures">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures"><span style="color: rgb(29, 148, 33); font-size: 18px; white-space: pre; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">//</span><span style="color: rgb(29, 148, 33); font-family: 'PingFang SC'; font-size: 18px; white-space: pre; font-variant-ligatures: no-common-ligatures;">创建摇一摇背景的小花图</span>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">backGround</span><span style="font-variant-ligatures: no-common-ligatures"> = [[</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIImageView</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">alloc</span><span style="font-variant-ligatures: no-common-ligatures">] </span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">initWithFrame</span><span style="font-variant-ligatures: no-common-ligatures">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">CGRectMake</span><span style="font-variant-ligatures: no-common-ligatures">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">imageView</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">center</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">x</span><span style="font-variant-ligatures: no-common-ligatures"> - </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">120</span><span style="font-variant-ligatures: no-common-ligatures">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">imageView</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">center</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">y</span><span style="font-variant-ligatures: no-common-ligatures"> - </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">200</span><span style="font-variant-ligatures: no-common-ligatures">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">240</span><span style="font-variant-ligatures: no-common-ligatures">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">400</span><span style="font-variant-ligatures: no-common-ligatures">)];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">NSString</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> *flowerStr = [[</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">NSBundle</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">mainBundle</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">]</span><span style="font-variant-ligatures: no-common-ligatures">pathForResource</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c91b13">@"flowers"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">ofType</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c91b13">@"png"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">backGround</span><span style="font-variant-ligatures: no-common-ligatures">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">image</span><span style="font-variant-ligatures: no-common-ligatures"> = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIImage</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">imageWithContentsOfFile</span><span style="font-variant-ligatures: no-common-ligatures">:flowerStr];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(83, 154, 164);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    [</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures">imageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">addSubview</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures">backGround</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: 'PingFang SC'; color: rgb(29, 148, 33);"><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">//</span><span style="font-variant-ligatures: no-common-ligatures">创建摇一摇上图</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">topImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = [[</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">alloc</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">] </span><span style="font-variant-ligatures: no-common-ligatures">initWithFrame</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures">CGRectMake</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures">CGRectGetMinX</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">backGround</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">), </span><span style="font-variant-ligatures: no-common-ligatures">CGRectGetMinY</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">backGround</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">), </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">240</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">200</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">)];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">NSString</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> *up = [[</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">NSBundle</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">mainBundle</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">] </span><span style="font-variant-ligatures: no-common-ligatures">pathForResource</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c91b13">@"up"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">ofType</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c91b13">@"png"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">topImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">image</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIImage</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">imageWithContentsOfFile</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:up];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(83, 154, 164);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    [</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures">imageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">addSubview</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures">topImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; min-height: 21px;"><span style="font-variant-ligatures: no-common-ligatures"><span style="color: rgb(29, 148, 33); font-size: 18px; white-space: pre; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">//</span><span style="color: rgb(29, 148, 33); font-family: 'PingFang SC'; font-size: 18px; white-space: pre; font-variant-ligatures: no-common-ligatures;">创建摇一摇下图</span>    </span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">downImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = [[</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">alloc</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">] </span><span style="font-variant-ligatures: no-common-ligatures">initWithFrame</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures">CGRectMake</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures">CGRectGetMinX</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">backGround</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">), </span><span style="font-variant-ligatures: no-common-ligatures">CGRectGetMidY</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">backGround</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">), </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">240</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">200</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">)];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">NSString</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> *down = [[</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">NSBundle</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">mainBundle</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">] </span><span style="font-variant-ligatures: no-common-ligatures">pathForResource</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c91b13">@"down"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">ofType</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c91b13">@"png"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">downImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">image</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIImage</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">imageWithContentsOfFile</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:down];</span> </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(83, 154, 164);"><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">    [</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures">imageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">addSubview</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures">downImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">}</span></p>
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">- (</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">void</span><span style="font-variant-ligatures: no-common-ligatures">)motionBegan:(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">UIEventSubtype</span><span style="font-variant-ligatures: no-common-ligatures">)motion withEvent:(</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIEvent</span><span style="font-variant-ligatures: no-common-ligatures"> *)event{</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">animateWithDuration</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">1.5</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">animations</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:^{</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">topImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">transform</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = </span><span style="font-variant-ligatures: no-common-ligatures">CGAffineTransformMakeTranslation</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">, -</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">topImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">size</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">height</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">);</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: 'PingFang SC'; color: rgb(29, 148, 33);"><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">    </span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">// </span><span style="font-variant-ligatures: no-common-ligatures">通过</span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">transform</span><span style="font-variant-ligatures: no-common-ligatures">设置平移举例</span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">x</span><span style="font-variant-ligatures: no-common-ligatures">为</span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">y</span><span style="font-variant-ligatures: no-common-ligatures">轴的平移距离</span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures">正数往右</span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures">负数往左</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: 'PingFang SC'; color: rgb(29, 148, 33);"><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">    </span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">//y</span><span style="font-variant-ligatures: no-common-ligatures">为</span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">y</span><span style="font-variant-ligatures: no-common-ligatures">轴的平移距离</span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">  </span><span style="font-variant-ligatures: no-common-ligatures">正数往下</span><span style="line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures">负数往上</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures">//transform</span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures;">是与进行平移之前进行比较</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">downImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">transform</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = </span><span style="font-variant-ligatures: no-common-ligatures">CGAffineTransformMakeTranslation</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">downImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">frame</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">size</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">height</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">);</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">    }</span><span style="font-variant-ligatures: no-common-ligatures; color: #5f31c1">completion</span><span style="font-variant-ligatures: no-common-ligatures">:^(</span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">BOOL</span><span style="font-variant-ligatures: no-common-ligatures"> finished) {</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">        [</span><span style="font-variant-ligatures: no-common-ligatures; color: #6122ae">UIView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">animateWithDuration</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">1.5</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> </span><span style="font-variant-ligatures: no-common-ligatures">animations</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">:^{</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">            </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">topImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">transform</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = </span><span style="font-variant-ligatures: no-common-ligatures">CGAffineTransformMakeTranslation</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">);</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(95, 49, 193);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">            </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275">self</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4">downImageView</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa">transform</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> = </span><span style="font-variant-ligatures: no-common-ligatures">CGAffineTransformMakeTranslation</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #0435ff">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000">);</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">         }</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">       ];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">     }</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">  ];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">}</span></p>



相关文章推荐

iOS微信朋友圈与摇一摇

本Demo为练手小项目,主要是熟悉目前主流APP的架构模式.此项目中采用MVC设计模式,纯代码和少许XIB方式实现.主要实现了朋友圈功能和摇一摇功能. 预览效果: WeChat_Demo.gi...

iOS-OC-仿微信摇一摇

// //  ViewController.m //  摇一摇 // //  Created by ZFJ_APPLE on 16/1/25. //  Copyright © 2016年 张...

iOS仿照微信摇一摇功能实现

iOS仿照微信摇一摇功能实现一、描述 需要做一个界面,仿照微信摇一摇,获取接口进行签到功能。 首先明确以下几点: 1、需要震动。 2、需要声音。(准备好mp3音...

IOS中微信摇一摇声音无法播放解决办法

在IOS中第一次调用play方法播放音频会被阻止,必须得等用户有交互动作,比如touchstart,click后才能正常调用,所以可以在摇一摇之前提醒用户点击一下开始游戏的按钮或者给用户一个弹窗,用户...

ios 摇一摇 仿微信

微信的摇一摇是怎么实现的~发现原来 ios本身就支持 在 UIResponder中存在这么一套方法   - (void)motionBegan:(UIEventSubtype)motion wi...

h5 + js 仿微信摇一摇

  • 2017年11月10日 17:57
  • 144KB
  • 下载

微信摇一摇实现

  • 2015年06月25日 20:50
  • 302KB
  • 下载

模仿微信摇一摇(只模仿传感器及震动)

参考链接: 主体内容参考:http://blog.csdn.net/catoop/article/details/8051835 看到http://104zz.iteye.com/blog/169...

ionic 完美仿微信摇一摇

  • 2016年03月23日 15:08
  • 5.67MB
  • 下载

仿微信摇一摇功能

  • 2016年06月22日 17:43
  • 1.43MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:iOS中制作微信摇一摇的图框雏形
举报原因:
原因补充:

(最多只允许输入30个字)