Sunday, 15 May 2011

ios - Resizable Centered Circular UIView -


I'm looking for a way to make a circle UIView which is resizable and remains centered ( View Image ). The pattern view in this example is a UIView subclass WCSDailyGoal .

ContainerView.m

  - (void) Make DELailyGoalView {_dailyGoalView = [[WCSDailyGoalView alloc] initWithFrame: CGRectMake (0, 0, 200, 200)]; _dailyGoalView.delegate = self; _dailyGoalView.goal = 200; _dailyGoalView.center = self.view.center; [Self.view addSubview: _dailyGoalView]; }  

WCSDailyGoal.m

  - (minus) set traps: (CGFloat) target {CGPoint saveCenter = self.center; CGRF Newframe = CGRactMake (Selffrafe.organ.x, SelfForm.origin.a, target, goal); Self.frame = newFrame; Self.layer.cornerRadius = Goal / 2.0; Self. Center = save center; }  

enter image details here

I was able to achieve this effect by creating a custom view (the following code in Swift):

 < code> Class ResizableCircleView: UIView {var maximum Sijhः CGFloat = 100 var minSize: CGFloat = 10 personal revenge Dragreknaijhr: UIPanGestureRecognizer! CurrentScale on Private: CGFloat = 1 Private defaultSize: CGFloat {return frame.width / currentScale} Override function layoutSubviews () {super.layoutSubviews () if dragRecognizer == zero {dragRecognizer = UIPanGestureRecognizer (target: auto, action: "handleDrag: ") addGestureRecognizer (dragRecognizer)} background color = UIColor.blackColor () layer.cornerRadius = frame.width / 2 clipsToBounds = true} handleDrag function (identifier: UIPanGestureRecognizer) {go inTopArea = recognizer.locationInView (self) .y & LT; New.size = frame.height + (inTopArea -1: 1) * dew newSize = minutes (MAXSIZE, newSize) newSize = maximum (minSize, newSize) currentScale = frame.height / 2 give DY = recognizer.translationInView (auto) Change the newSize / defaultSize = CGAffineTransformMakeScale (currentScale, currentScale) recognizer.setTranslation (CGPointZero, in mind: keeping in mind)}}  

Setting the desired values ​​for you maximum and minimum size You can adjust maximum size and minimum size . Hope this will help.


No comments:

Post a Comment