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-OC-仿微信摇一摇

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

仿微信摇一摇 ios

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

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

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

iOS实现摇一摇基本思路

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

iOS 摇一摇判断要了多少秒

要做一个摇奖的功能,持续摇晃2、4、6分别得到不同的礼物,检测摇动时间的代码如下: CMMotionManager *_motionManager = [[CMMotionManager ...
  • workhardupc100
  • workhardupc100
  • 2013年05月11日 09:12
  • 1896

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

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

关于ios里的摇一摇以及播放声音和震动

使用AudioServicesPlaySystemSound 这个接口来进行声音和震动的播放, 当然需要在工程中加入AudioToolBox.framework 1. 播放震动 ...
  • reims2046
  • reims2046
  • 2014年04月29日 15:35
  • 1696

Android 微信摇一摇功能实现

开发之前 今天学习了一下传感器, 脑子里就蹦出了微信的摇一摇, 于是鼓了鼓勇气抽空写了出来, 本人菜鸟一枚, 希望大神们多多指点 开发环境 Android Studio 2.2.1 JDK1.7 ...
  • u013144863
  • u013144863
  • 2016年10月28日 18:27
  • 3045

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

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

ArcGIS问题:图框的制作

ArcGIS图框的制作。打开所有文档,包括出图的掩膜文件。
  • u010687924
  • u010687924
  • 2015年03月23日 17:36
  • 921
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:iOS中制作微信摇一摇的图框雏形
举报原因:
原因补充:

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