【问题标题】:how to convert UIView code into UIViewController with Nib in ipad如何在 ipad 中使用 Nib 将 UIView 代码转换为 UIViewController
【发布时间】:2013-05-01 00:03:38
【问题描述】:

我找到了我想在我的视图控制器中实现的教程,但代码是用UIView 编写的,所以如何将UIView 代码转换为UIViewController 它可以在这里工作是我的代码

  #import <UIKit/UIKit.h>


  @interface MyLineDrawingView : UIView {

  UIBezierPath *myPath;
  UIColor *brushPattern;
  }

  @end


   #import "MyLineDrawingView.h"


   @implementation MyLineDrawingView

   - (id)initWithFrame:(CGRect)frame
 {

   self = [super initWithFrame:frame];
    if (self) {
    // Initialization code

    self.backgroundColor=[UIColor whiteColor];
    myPath=[[UIBezierPath alloc]init];
    myPath.lineCapStyle=kCGLineCapRound;
    myPath.miterLimit=0;
    myPath.lineWidth=10;
    brushPattern=[UIColor redColor];
    }
   return self;
   }

仅当您执行自定义绘图时才覆盖drawRect:。 空实现会对动画期间的性能产生不利影响。

 - (void)drawRect:(CGRect)rect
 {

 [brushPattern setStroke];
 [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
 // Drawing code
 //[myPath stroke];
 }

  #pragma mark - Touch Methods

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath moveToPoint:[mytouch locationInView:self]];

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

     {
         //handle touch event

      }

【问题讨论】:

标签: iphone xcode ipad uiview uiviewcontroller


【解决方案1】:

创建一个UIViewController 对象并将视图属性设置为此视图。这样的事情应该可以工作。

UIViewController *vc = [[UIViewController alloc] init];
MyLineDrawingView *myView = [[MyLineDrawingView alloc] init];
vc.view = myView;

【讨论】:

    猜你喜欢
    • 2012-09-21
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 2012-05-07
    • 2011-07-23
    • 2017-10-26
    相关资源
    最近更新 更多