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中微信摇一摇声音无法播放解决办法

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

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

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

仿微信摇一摇 ios

iOS 中有摇动要实现的方法: - (void)motionBegan:(UIEventSubtype)motion withEvent:(nullable UIEvent *)even...
  • sinat_29789455
  • sinat_29789455
  • 2016-07-07 16:11:14
  • 683

iOS-OC-仿微信摇一摇

// //  ViewController.m //  摇一摇 // //  Created by ZFJ_APPLE on 16/1/25. //  Copyright © 2016年 张...
  • u014220518
  • u014220518
  • 2016-01-25 14:59:54
  • 1838

iOS实现摇一摇基本思路

在微信中有一个摇一摇功能,在一些彩票类APP中也有一个摇一摇随机选号的功能,类似的一些摇一摇功能实现起来都是很简单的,下面以微信摇一摇功能来介绍实现原理 在iOS中系统默认为我们提供了摇一摇的功能检...
  • qq_33856343
  • qq_33856343
  • 2016-08-11 11:39:04
  • 680

iOS开发——全局响应MotionEvent(微信摇一摇)

遇到这样一个需求:应用无论处于哪个view controller,摇动手机,都能够出发某一方法。 能够想到的思路就是用苹果封装好的“MotionEvent”,但是如果简单的把一下代码加到某一vi...
  • haogaoming123
  • haogaoming123
  • 2015-04-03 16:18:58
  • 1689

高仿微信摇一摇,动画效果为左右晃动

学习到东西,发出来帮助更多的人,做一个有奉献精神的人! 原文地址;http://blog.csdn.net/catoop/article/details/8051835,原博主实现了摇一摇 在...
  • sx1650840284
  • sx1650840284
  • 2016-11-04 00:09:55
  • 856

iOS微信摇一摇功能

这样,公司项目中需要一个摇一摇抽奖的模块,之前没有了解,当实现起来的时候发现特别简单,因为苹果官方有指定方法可以调用。来吧,直接开始。 - (void)viewDidLoad {     [su...
  • lhycjoker
  • lhycjoker
  • 2016-03-22 10:21:11
  • 344

微信摇一摇-----加速度传感器的使用

一款手机的传感器的种类是很多的,像米4, 竟然有26种传感器!!其实微信里的摇一摇,就是一种加速度传感器实现的。代码如下: public class MainActivity extends ...
  • AndroidStudioo
  • AndroidStudioo
  • 2016-08-01 23:11:37
  • 1456

iOS 测试手机是否震动(类似微信摇一摇功能)

1、在  AppDelegate.h 中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOpti...
  • sevenquan
  • sevenquan
  • 2016-02-19 17:52:32
  • 1355
收藏助手
不良信息举报
您举报文章:iOS中制作微信摇一摇的图框雏形
举报原因:
原因补充:

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