# Animating a view around another view on iOS

Language: en
Canonical: [Animating a view around another view on iOS](<https://allluckly.cn/en/journal/2015-07-29-animating-a-view-around-another-view-on-ios/>)
中文：[中文 HTML](<https://allluckly.cn/ios%E5%8A%A8%E7%94%BB/iOS%E5%BC%80%E5%8F%91%E5%8A%A8%E7%94%BB%E4%B9%8B%E7%BB%95View%E6%97%8B%E8%BD%AC%E7%9A%84View>)
English: [English HTML](<https://allluckly.cn/en/journal/2015-07-29-animating-a-view-around-another-view-on-ios/>)
Published: 2015-07-29T00:00:00+08:00
Modified: 2026-10-23T10:34:09+08:00
Author: [Bison](<https://allluckly.cn/about/>)

Explains how to move a view around the centre of an image. Trigonometric functions calculate points on a circle, and updating the view coordinates produces an orbiting animation without a complex animation framework.

Originally credited to Bison. Content is retained as published.

English translation of the [Chinese original](<https://allluckly.cn/ios%E5%8A%A8%E7%94%BB/iOS%E5%BC%80%E5%8F%91%E5%8A%A8%E7%94%BB%E4%B9%8B%E7%BB%95View%E6%97%8B%E8%BD%AC%E7%9A%84View>), translated on 2026-10-23. The article body uses automated translation; app descriptions, historical reading notes and video subtitles receive separate editorial checks. Original publication dates, attribution, code and version notes are retained.

**Before you read** This technical note dates from 2015–2017. The examples have not been rerun as part of this archive update. Read API, dependency and tool details in the context of the original publication date.

> "Health is the foundation of everything. Getting more exercise is the way to go." Bison

A recent project needed an animation, so I looked through a lot of related material.  
 I found nothing suitable, so I made a custom implementation.  
 The main principle uses the sine rule for triangles   
 and the cosine rule to animate a view moving around an image's center.

See the code below.

Core code

```css
self.center = CGPointMake(_radius * cosf(_angle) + imgView.center.x, _radius * sinf(_angle) + imgView.center.y);

_timer = [NSTimer scheduledTimerWithTimeInterval:_time target:self selector:@selector(moveView) userInfo:nil repeats:YES];
```

> [Click to download the demo](<https://github.com/AllLuckly/RadiusOperation>)

![(RadiusOperation)](<https://github.com/AllLuckly/RadiusOperation/blob/master/123.gif?raw=true>)

