Tag: uiview

如何在用户的不同视图上注册触摸,将手指拖动到新的位置?

假设我在iOS应用程序中有一个leftView和一个rightView。 现在这两个观点都是独立注册触摸。 如果我将手指从左侧视图拖到右侧视图,则左侧视图将继续注册触摸,即使我的手指现在处于右侧视图中。 除非我抬起手指再次触摸右侧的视图,否则右侧视图不会注册触摸。 任何人有任何想法如何处理这个?

如何获得项目的坐标,而它是animation?

我可以像这样在屏幕上制作一些animation: aView.frame = CGRectMake(100,100,50,50); [UIView animateWithDuration:25.0 delay:0.0 options:UIViewAnimationCurveLinear animations: ^{ aView.frame = CGRectMake(200,100,50,50); } completion:^(BOOL finished) { aView.hidden = YES; } ]; ..但是如何获得物品在animation时的位置? 如果我把一个button在屏幕上,并使用此操作 -(IBAction)buttonTapped:(id)sender { NSLog(@"x pos:%f", aframe.origin.x)l } 那么我所得到的就是 x pos:200.00 ..这是该项目的最终位置,但不是目前的。 我如何获得最新的?

我如何添加跨越两个视图的渐变?

我知道该怎么做(1)但我该怎么做(2)? UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = view.bounds; gradient.colors = @[(id)[UIColor blueColor].CGColor, (id)[UIColor redColor].CGColor]; [view.layer insertSublayer:gradient atIndex:0];

animation时更新视图的框架

我正在做这样的animation: CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; animation.duration = 100.0; animation.path = self.animationPath.CGPath; [view.layer addAnimation:animation forKey:@"animation"]; 工作正常,但是,现在尝试检测在屏幕上移动的对象的触摸时失败: – (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { for (UIView* subview in self.subviews ) { if ( [subview hitTest:[self convertPoint:point toView:subview] withEvent:event] != nil ) { [self handleTap]; return YES; } } return NO; } 它失败了,因为视图的框架不再是它在animation时在屏幕上的明显位置。 我怎样才能让pointInside与正在animation的视图一起工作?

添加新的ViewController的视图作为子视图

我正在尝试以下,未能添加新的viewcontrollers视图。 是否只能呈现视图控制器? 我们不能添加视图从其他故事板viewcontrollers视图? //Working let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController self.present( viewcontroller , animated: true, completion: nil) //Not working let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController vc.view.frame = self.view.frame self.view.addSubview(vc.view)

UIView方法swizzling swift 3

我正在尝试在swift中快速实现方法3基于答案如何实现方法swizzling swift 3.0? 这是我的代码: // MARK: – Swizzling private let swizzling: (UIView.Type) -> () = { view in let originalSelector = #selector(view.awakeFromNib) let swizzledSelector = #selector(view.swizzled_localization_awakeFromNib) let originalMethod = class_getInstanceMethod(view, originalSelector) let swizzledMethod = class_getInstanceMethod(view, swizzledSelector) method_exchangeImplementations(originalMethod, swizzledMethod) } extension UIView { open override class func initialize() { guard self === UIView.self else { return […]

在MKMapView上添加一个UIView

我试图把一个button在我的MKMapView的angular落,以控制地图保持locking在用户的位置。 我想到的是创build一个带有button的UIView ,并将其添加到我的MKMapView (不作为注释或其他东西),我不能用Interface Builder来解决这个问题。 如何以编程方式添加此button? 控制它是否真的跟随用户等已经sorting – 只需要button。

使用CGAffineTransformMakeScale的UIViewanimation以十进制数字立即改变大小

– (void)startAnimation { //reverse – shrinking from full size if (_reversed == YES) { //self.transform = CGAffineTransformMakeScale(1.0, 1.0); [UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^{ self.transform = CGAffineTransformMakeScale(0.1, 0.1); //this line does it instantly self.alpha = 0; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } else { //non reverse – expanding from middle self.transform = CGAffineTransformMakeScale(0.001, 0.001); […]

停止UIView中的所有asynchronous任务

我正在创build一个在UIViewController运行许多asynchronous任务的UIView 。 在某些时候,我希望能够移除UIView并停止所有正在运行的任务。 但是,调用removeFromSuperview()不会停止任务。 有没有办法可以做到这一点? 示例代码 class ViewController: UIViewController { let v = SomeView() override func viewDidLoad() { super.viewDidLoad() v.frame = CGRect(x: 0, y: 0, width: 10, height: 10) self.view.addSubview(v) let v1 = UIButton() v1.frame = CGRect(x: 0, y: 0, width: 100, height: 100) v1.backgroundColor = UIColor.blue v1.addTarget(self, action: #selector(removeV(_:)), for: .touchUpInside) self.view.addSubview(v1) } func […]

iOS:在UI(子)视图中处理UIGestureRecognisers

我想知道如何最好地解决以下问题: 我有一个单一的ViewController。 它的视图包含大量复杂的子视图(UIView的子类)。 由于这些UIViews的复杂性,初始化他们自己的UIGestureRecognisers并且执行相应的目标动作。 由于我想协调各种子视图的手势,我必须将单个ViewController设置为手势的委托。 这有很多种可能性。 1)初始化viewController中的所有手势(这将导致大量的viewController) 2)在UIVIews(getViewController)中定义一个协议,由ViewController实现 @protocol CustomViewDelegate <NSObject> @required – (UIViewController *)getViewController; @end 3)自定义UIViews的init方法,并使用ViewController作为选项。 – (id)initWithFrame:(CGRect)frame andViewController:(UIViewController *)vc; 解决这个问题最高雅的可能性是什么? 在UIView对象中实现目标动作可以吗? 感谢您的想法…